I have a prefab which is instantiated in the Scene and what i am trying to do is to disable with a (touch or timeCounter ) but sometime it disables all the instances of prefab and sometimes 2 or 3 of them.
i want to disable particular object which i have touched currently.
Here is my code:
void Update () {
blastingTimeCounter -= Time.deltaTime;
if (blastingTimeCounter <= 0) {
DestroySquare ();
}
for (int i = 0; i < Input.touchCount; i++) {
if (Input.GetTouch (i).phase == TouchPhase.Stationary) {
hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (Input.GetTouch (i).position), Vector2.zero);
if (hit.collider != null) {
DestroySquare ();
}
}
}
}
void DestroySquare(){
gameObject.SetActive (false);
blastingTimeCounter = blastingTime;
}
Any Help will be Appreciated…