- Home /
Destroy Other
I want to make it so that when the player touches this object, it destroys a different object.
I attach this script to the trigger, so that way when the player touches this trigger, a separate object called "Sucks2" is destroyed.
function OnTriggerEnter(other : Collider) {
if (other.tag == "Player") {
Destroy(gameObject.name == "Sucks2");
}
}
but I get this error message: "BCE0020: An instance of type 'UnityEngine.Object' is required to access non static member 'name'."
why? how do I fix this?
Answer by robertbu · Aug 26, 2014 at 03:05 PM
Change:
Destroy(gameObject.name == "Sucks2");
To:
Destroy(GameObject.Find("Sucks2"));
Note this line of code will cause problems if no game object with 'Sucks2' name is in the scene.
Your answer
Follow this Question
Related Questions
When I kill one enemy, the rest disapear, but still shoot 1 Answer
Error BCE0044 JavaScript 1 Answer
Incremental game need help 1 Answer
How i make this code in Unity Javascript 2 Answers
Script copied exactly, yet I get the console errors 1 Answer