Search Unity

Android Touch Input help (JavaScript)

Discussion in 'Scripting' started by RSharma98, May 22, 2015.

  1. RSharma98

    RSharma98

    Joined:
    Apr 27, 2014
    Posts:
    21
    Hi. I'm new to unity and was wondering if someone could help me with this? I've been trying to export my game of Pong from PC to Android but have been stuck with getting Android touch to work. I've looked at various other forums, looked at the Unity Docs and even looked at other answers and asked a few myself, but it seems like I'm getting nowhere. After a lot of redrafting, my code now looks like this:

    1. functionUpdate(){
    2. var touch :Touch;
    3. if(Input.touchCount ==1){
    4. if(touch.position.y >Screen.height/2){
    5. rigidbody2D.velocity.y = speed;
    6. }
    7. if(touch.position.y <Screen.height/2){
    8. rigidbody2D.velocity.y = speed*-1;
    9. }
    10. }
    11. }
    But the problem is that it does absolutely nothing! No matter where I tap on my screen, the player does not move. Does anyone know what is wrong? Any help would be appreciated and thank you in advance