- Home /
Question by
Makarew · Sep 28, 2015 at 06:38 AM ·
touchtouchscreenteleport
Android touch teleport
I'm making a game for Android. I want it to teleport an object to wherever I touch on the screen. However, what happens when I touch is that the object just disappears.
Here's my code. using UnityEngine; using System.Collections;
public class Touch : MonoBehaviour {
public GameObject cube;
void Update() {
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
Vector2 touchSpot = Input.GetTouch(i).position;
cube.transform.position = touchSpot;
}
}
}
}
Comment
Answer by shieldgenerator7 · Dec 29, 2015 at 04:10 AM
You have to use Camera.main.screenPointToWorldPosition() or something like that. It's mentioned in a few of the other answers.