public Rigidbody bullet; //check reference in Inspector
public float power = 1500f;
public float moveSpeed = 2f;
void Update () {
float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(h, v, 0);
Rigidbody myClone = null;
//For editor
#if UNITY_EDITOR
if(Input.GetMouseButtonDown(0)) {
Vector3 pos = Input.mousePosition; //get screen position of mouse
//Calculate screen position of touch in position in world, "z" component is more 0, example 0.3f - default near clip plane for perspective camera
Vector3 p = Camera.main.ScreenToWorldPoint(new Vector3(pos.x, pos.y, Camera.main.nearClipPlane));
//Set new position "p"
myClone = Instantiate(bullet, p, transform.rotation) as Rigidbody;
myClone.AddForce(power*Camera.main.transform.forward);
}
#endif
//For touch
#if UNITY_ANDROID || UNITY_IPHONE
if (Input.touchCount > 0) {
for(int i = 0; i < Input.touchCount; i++) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
Vector3 pos = Input.GetTouch(i).position; //get screen position of touch
//Calculate screen position of touch in position in world, "z" component is more 0, example 0.3f - default near clip plane for perspective camera
Vector3 p = Camera.main.ScreenToWorldPoint(new Vector3(pos.x, pos.y, Camera.main.nearClipPlane));
//Set new position "p"
myClone = Instantiate(bullet, p, transform.rotation) as Rigidbody;
myClone.AddForce(power*Camera.main.transform.forward);
}
}
}
#endif
}
you are adding your i integer the first time you enter your touch count by one so next time this statement i< Input.touchCount is false and nothing will happen you should
check