Search Unity

Player Controller help with touch controls

Discussion in 'Scripting' started by iinot, Mar 1, 2015.

  1. iinot

    iinot

    Joined:
    Jan 20, 2015
    Posts:
    10
    Can someone please give me an example of a touch control script that works,

    I've tried the sample Input.GetTouch and it doesn't work,

    1. Can someone please provide me a working touch player control script that:
    a. when the player taps the screen the player object moves towards that direction for a certain distance
    b. also set a rate of tapping so they cannot spam the movement
    c. call a sprite when the screen is touched e.g. the rocket will show a thrusting flare if the screen is touched to represent movement

    2. How do I test this is unity game scene preview since I cannot use touch, How do i set my mouse left click to represent touch.

    I am still in the learning phase of C# it would be really helpful and appreciated any one provide me a sample script for me to work on.

    This is a 2D game!

    Cheers,

    Tony
     
  2. iinot

    iinot

    Joined:
    Jan 20, 2015
    Posts:
    10
    publicclassRocketMovement : MonoBehaviour {

    publicfloatspeed;
    privateVector3target;



    //Initalisation
    voidStart () {
    target = transform.position;
    }


    //InputandGraphics
    voidUpdate () {
    if (Input.GetMouseButtonDown(0)) {
    target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    target.z = transform.position.z;
    }
    transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
    }

    }


    How do I get gravity working with this script because its horrible with gravity.
    Also how do I only make it so that the object only travels a certain distance to the touch/mouse position and not all the way?

    Please help thanks!