Hello everyone! i have a problem with an android game: i’ve written this code to instantiate a prefab at the touch position but the object (a projectile) is always instantiated at the center of the screen. What’s wrong?
function Update () {
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
var touchPos = Input.GetTouch(i).position;
var createPos = myCam.ScreenToWorldPoint(touchPos);
Instantiate (projectile, Vector3(createPos.x, createPos.y, 4), Quaternion.identity);
}
}
}