- Home /
Destroying Multiple Objects with Tags
I am trying to destroy a grid when a button is pressed. Each grid square is a child of one other one. This script is attached to the button.
#pragma strict
function OnMouseEnter ()
{
renderer.material.color = Color.red;
}
function OnMouseExit ()
{
renderer.material.color = Color.white;
}
function OnMouseUp ()
{
var grid = GameObject.FindWithTag("Grid");
renderer.enabled = false;
}
Be more specific, i re-read you question 3 times, and still isn't sure what do you want. What should be destroyed, what does changing button color does have to do with grid destroy, how are you accessing button, what IS grid square etc.
Answer by meat5000 · Aug 22, 2013 at 11:12 PM
Try this instead
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html
What you are using is only finding one object. The reference here tells you how to enumerate all the objects into an array. You can do what you want with them from there. The example should be in the reference of how to do this.
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Delete some unused tags and game objects tag changes unity 5 2 Answers
GameObject.FindWithTag doesn't work! 1 Answer
When all objects with a certain tag has been destroyed, load the next level! 3 Answers
How do I make Destroy(gameObject) work in my script? 1 Answer