- Home /
Deleting one object, not all objects at once.
I have a script that deletes an object that is called a certain name "Object 1" when it is clicked. I have the script attached to all of my gameobjects and it works fine. I can click every other object and it doesn't trigger the deletion. As soon as I click the object that should be deleted, it deletes ALL of my other objects with the script attached. Here is my code for deletion:
if(Box.collider.gameObject.name == "DeleteMe")
{
Destroy(this.gameObject);
}
else
{
}
I have tried using this.gameObject and just gameObject, it still deletes all objects with the script attached to. I'm using c#, if anyone could help it would be great thanks. I'm new to unity so excuse if I've made a stupid error!
Answer by Chumm · Nov 02, 2013 at 02:29 PM
Fixed if anyone wants to see:
Instead of destroying this.gameObject, you destroy Box.collider.gameObject. Doh!
Your answer
Follow this Question
Related Questions
NullReferenceException - When destroying Object 1 Answer
destroy object in front of an other object? 1 Answer
if object is destroyed 2 Answers
Distribute terrain in zones 3 Answers
How to cleanly delete Object with attached Bounding Box Rig (Script)? 0 Answers