Hello. I recently created a JavaScript code to make my game work on Android but it does not do what I intended it to do. I have tried everything yet for some reason my code does not work! All I want is for the code to make my player move up or down depending on which half of the screen is pressed. Does anyone know what is wrong? Code (JavaScript): #pragma strict var speed:float=15; function Update () { var touch : Touch; if (Input.touchCount>1) { if (touch.position.y > Screen.width/2){ GetComponent.<Rigidbody2D>().velocity.y = speed; } if (touch.position.y < Screen.width/2){ GetComponent.<Rigidbody2D>().velocity.y = speed*-1; } } else{ GetComponent.<Rigidbody2D>().velocity.y=0; } } I tried to export the game to my Android phone, but whenever I tap the screen the player only moves down, never up. Does anyone know what is wrong? I would really appreciate any help and thank you in advance if anyone knows how to fix this.
Not sure about UnityScript but in C# you need to address Input.GetTouch. See Unity reference below. http://docs.unity3d.com/ScriptReference/Input.GetTouch.html
I'm not great with JavaScript but I don't see where you assign your touch variable to anything. Trying to access touch.position.y probably returns null or 0, regardless of where you touch the screen.