When I touch the screen with the following code, the program fires missiles. The issue being that it appears to be firing two missiles at once. One missile travels to the touch location and explodes. The second instantiates and then explodes at the origin point. This is only occurting when I test on my devices and makes it very difficult for me to debug.
if(Input.touchCount>0 && Input.GetTouch(0).phase==TouchPhase.Began){
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(ray) && ray.origin.y>player.transform.position.y){
if(!player.GetComponent<Player>().StaminaEmpty()){
touchLoc=ray.origin;
Instantiate(Resources.Load("blast",typeof(GameObject)));
}
}
}
I have Unity Remote up and running correctly. This shows me that touching the screen once is causing two missiles to spawn. I checked that my script is not attached to any other objects in the scene except for the one that I want it on. It seems to be responding as if I’ve TouchPhase.Began twice
Ah ha! So, it turns out that my temporary function to read mouse functions was creating a second instantiation of each missile fired by touch. Clearly an issue of my not having had Unity Remote running previously.