Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Replace Input.GetAxis with Touch

$
0
0
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.

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>