Search Unity

Mobile script using Mouse input instead of touch input

Discussion in 'Android' started by Pandamonium99, Jul 16, 2014.

  1. Pandamonium99

    Pandamonium99

    Joined:
    Jul 16, 2012
    Posts:
    14
    I'm making a game where I need to move the "player" based on where the person is touching the screen. I devised a script to do just that, but it is not responding to "touches". Actually the script only works if I add an Input listener for a "Mouse", not a "Touch" for mobile device. The code looks like this:
    Code (JavaScript):
    1.     if(platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer){
    2.        if(Input.touchCount > 0) {
    3.        
    4.            
    5.          if(Input.GetTouch(0).phase == TouchPhase.Began){
    6.          left = true;
    7.           checkTouch(Input.GetTouch(0).position);
    8.          
    9.        
    10.          }
    11.          if (Input.GetTouch(0).phase == TouchPhase.Ended) {
    12.          left = false;
    13.          gameObject.GetComponent(Rigidbody2D).velocity = Vector2(0,gameObject.GetComponent(Rigidbody2D).velocity.y);
    14.        gameObject.GetComponent(Rigidbody2D).angularVelocity = 0;
    15.          }
    16.          }
    17.     }
    18.