Question by
zico_mahilary · Aug 20, 2016 at 05:16 PM ·
androidtouchdestroytap
destroy gameObject on touch
Please tell me how to detect touch on a gameObject with the tag "Enemy" on it. There will be several gameObjects with the tag "Enemy"on screen at the same time. But only the one that is touched should get destroyed.
this is what ive got till now: using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
void Start () {
}
void Update()
{
for (var i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray))
{
if(tag == "Enemy")
Destroy(this.gameObject);
}
}
}
}
}
This is destroying all game objects with the tag. But only the one touched should get destroyed. Please help me
Comment
Your answer
Follow this Question
Related Questions
Android Build Bug 0 Answers
What is the best way to implement a more responsive custom drag event with Scroll Rect? 0 Answers
Two finger tap causes jump bug 0 Answers
buttons vs touch. 1 Answer