I have a prefab which is instantiated in the scene ( 6 copies of prefab). I am trying to disable it with a touch on it , but when i tap on it it disables all the gameObjects of the prefab.
I am using single Script to destroy it.
i can’t figure what is happening.
Can anyone check what 's wrong i am doing here…
void Update () {
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 && hit.transform.gameObject.tag == "BlackSquare")
ClickedDown (hit.collider);
}
}
void ClickedDown(Collider2D collider){
Instantiate (blastEffect,transform.position,transform.rotation);
this.gameObject.SetActive (false);
waitForSecondsCounter = waitForSeconds;
Color c = this.transform.GetComponent <SpriteRenderer>().color;
c.a = 1f;
this.transform.GetComponent <SpriteRenderer> ().color = c;
}