Is there a way of converting this:
moveHorizontal = Input.GetAxis ("Horizontal");
moveVertical = Input.GetAxis ("Vertical");
transform.Translate (Vector3.right * moveHorizontal * speed * Time.deltaTime);
transform.Translate (Vector3.forward * moveVertical * speed * Time.deltaTime);
...so that it would work for touch?
I made buttons on my game where if I touch the up arrow key using my Android, it would go forward as if I pressed the up arrow key on my keyboard.
My touch code is currently this one, but it just detects the touch, it doesn't really move anything.
if (Input.touchCount > 0)
{
Touch theTouch = Input.GetTouch (0);
Ray ray = Camera.main.ScreenPointToRay(theTouch.position);
if(Physics.Raycast(ray, out hit) && hit.transform.tag == "UpButtonTag")
{
if(Input.touchCount == 1)
{
if (theTouch.phase == TouchPhase.Stationary || theTouch.phase == TouchPhase.Moved)
{
Debug.Log ("The Up Button is pressed!");
}
}
}
}
I have many more of these for the Left Button, Right Button, Down Button, etc, but I still don't know how to make it move my player like from the code above.
Thanks! I know someone already asked this question here, but its answers didn't work for me, and the asker didn't also chose a correct answer.
↧