- Home /
Destroy at collision based on color
I'm really new to Unity, I was wondering how I would go about the following collision: Two spheres destroy on collision if they are the same color . Any advice or scripts would be awesome!? Thank you!
Answer by aldonaletto · Oct 19, 2011 at 10:20 PM
The easiest way would be to add this same script to all spheres, no matter which color they are:
function OnCollisionEnter(other: Collision){ var myColor = renderer.material.color; var otherColor = other.transform.renderer.material.color; if (myColor == otherColor){ // if colors are the same... Destroy(gameObject); // suicide } }
NOTE: the spheres must have rigidbodies (at least one of the spheres) for collisions to be detected.
Answer by NickleKoch · Oct 20, 2011 at 12:39 AM
Thank you!!
$$anonymous$$ark the answer as correct and don't use the "answer" field to comment, for that click "add a new comment" under the question.
Answer by akashtechdeveloper · Aug 14, 2021 at 06:58 AM
I can't understand please make video on YouTube
Your answer
Follow this Question
Related Questions
C#: Changing current position of an object in y. 1 Answer
Error message from console after destroying an Object with sound Logical Error ? 1 Answer
how to: Player hits enemy and enemy dissappears? 2 Answers
i'm trying to code a premise, if 3 objects are the same color then it will destroy the wall 1 Answer
Why won't this object destroy? 2 Answers