/Scripts/AcidBase.js

http://acid-and-base.googlecode.com/ · JavaScript · 31 lines · 26 code · 5 blank · 0 comment · 8 complexity · 2ba168c710225ace616f89f9e1eb5513 MD5 · raw file

  1. private var enable : boolean;
  2. private var txt : String;
  3. function Star(){
  4. enable = false;
  5. txt = "";
  6. }
  7. function OnCollisionEnter (col : Collision) {
  8. if(col.collider.GetComponent(Properties) && gameObject.GetComponent(Properties)){ //If the objects contain chemical properties
  9. var oneProperties = gameObject.GetComponent(Properties);
  10. var twoProperties = col.collider.GetComponent(Properties);
  11. if(oneProperties.ph < 7 && twoProperties.ph > 7){//Acid + Base...
  12. txt = "Acid + Base";
  13. }
  14. else if(oneProperties.ph > 7 && twoProperties.ph < 7){//Base + Acid...
  15. txt = "Base + Acid";
  16. }
  17. enable = true;
  18. yield WaitForSeconds(2.0);
  19. enable = false;
  20. }
  21. }
  22. function OnGUI () {
  23. if (enable){
  24. GUI.Label (Rect (Screen.width/2 - 50, Screen.height/2 - 10, 100, 20), txt, "box");
  25. }
  26. }