- Home /
How can I make multiple collision detections work with one object?
I have a little cube player and it have it colliding with the floor. It works properly and loads up a scene, but when i try to get the player to collide with a different object to "collect" it, its as if its colliding with the floor and loads up the "game over" scene. So to recap, no matter what the player collides with, it will always "die". Anyone know whats going on? Thanks :)
Well, you could start by posting the code you're using that triggers the "die"...
But my guess is that you're not putting a Condition before the "die" to check what type of object is being collided with. If this was C#, here is an example of how it would be structured:
void OnCollisionEnter2D(Collider2D other)
{
if(other.gameObject.tag == "Wall")
{
doWhatWeWant;
}
else if(other.gameObject.tag == "Floor")
{
doWhatWeWant;
}
else if(other.gameObject.tag == "coin")
{
doWhatWeWant;
}
}
But this is only 1 scenario for one purposes... We need more info about your scripts, or you should just read up more on how to handle event Triggering on Collision in Unity. There are tonnes of resources out there on the subject.
Answer by TheHoongs · Jan 11, 2014 at 04:02 PM
Probably by putting multiple triggers.If not,ignore this.
Your answer
Follow this Question
Related Questions
Checking collision direction. 1 Answer
Explosion triggering another explosion 1 Answer
Collision Response Algorithm for 3D Axis-Aligned Box Collider 1 Answer
OnCollision2D will not work for me 1 Answer
Trigger a color change via collide 1 Answer