- Home /
How can i destroy spawned objects according a indicator?
Hi Guys. I have 7 Spawned objects and i have a random changed indicator with every played game. This indicator are have 7 Color/Tag. And 7 spawned objs. are have 7 tag one by one. I want, if this objects tag, are equal tag of indicator. i want destroy spawned objs one by one with mouse click. i tried many way but i can not do this. Please help me. And Sorry for my bad eng.
Answer by rebelarcher · Jul 26, 2018 at 11:12 AM
i hope this img helps you
Answer by AdityaViaxor · Jul 26, 2018 at 12:59 PM
Simple, make a script which will be on GameManager(Empty gameobject) and Get Reference of Indicator and from that reference get tag/color of indicator then in other remaining cubes(object) have their own script now in cube script get the tag of indicator from GameManager script below is demo., 1) Create GameManager empty game object attach script Color_Colletctor (or any name)
{
public class Color_Collector: Monobehavior
string colorTag
public GameOBject Indicator;
{
Update()
{
colorTag = Indicator.Tag;
}
}
}
2) Script on other 6 cube (make one script and attach to all) Cube.cs
{
public class Cube: Monobehaviour
{
public Gameobject GameManagrer;
void Update()
{
if(input.GetMouseButtonDown(0))
{
if(GameManager.color==this.gameobject.color)
{
Destroy (this.gameObject);
` }
}
}
}
}
i using 7 objects in indicator. Those are random spawning. And 7 different objects are spawning. they are have same tag. Just we can use the tag ?
buddy no need to use 7 different object use one object just change color of that and tag it would be more efficient way. when you spawn indicator just change color on start or onEnable function. and set tag programmatically make "string tag" variable and when cube spawn set random color and set the same name as a tag