- Home /
Use touch to spawn a prefab
I am trying to use touch to spawn a clone of a prefab every time the screen is tapped. I'm not used to using touch. I would use onmousebuttondown but that doesn't work with my pause button. How would I go about using touch to spawn an object?
Answer by etopsirhc · Jul 23, 2017 at 01:22 AM
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began){
//instantiate your thing here
}
Thank you. Now the problem is that when I tap my pause button, and then click resume, two balls will spawn. I added a line of code but it doesn't seem to be working:
void Update () { var pointerOverObject = UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject();
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began && !pointerOverObject){ Instantiate (Ball, transform.position, Quaternion.identity); GameObject.Find ("Dropper first frame").GetComponent ().Play ("DropperAnimation");
Your answer
Follow this Question
Related Questions
Merging touches 0 Answers
Touch.Phase Differences ? 2 Answers
Check whether touch is held 0 Answers
How to get multitouch input using EasyTouch 0 Answers
Touch goes through UI button 1 Answer