- Home /
Question by
caleb_b · Apr 12, 2014 at 01:15 AM ·
c#gameobjectdestroy
Destroy a gameobject from a script on a different game object by tag?
I have an empty game object called GameController, with a script attached by the same name. Here is an exerpt from that script that applies to this question
void Update ()
{
if (restart)
{
if (Input.GetKeyDown (KeyCode.R))
{
Application.LoadLevel (Application.loadedLevel);
}
}
}
I want this script to destroy a GUIText tagged "IText" when R is pressed. This would go under the input.getkeydown If statement, but when I add
Destroy(gameObject.tag = "IText");
below the application.loadlevel, I get a bunch of errors. How should I be wording this
Comment
Best Answer
Answer by Jun Hin · Apr 12, 2014 at 01:35 AM
You need: Destroy (GameObject.FindWithTag("IText"));
Your solution worked, but it didn't do what I thought it would do. Thanks for the answer though!