- Home /
can my player collide with more than one objects?
in my game i am trying to get my player to collide with two objects on the scene, right now only one is working(collision), this is what i have:
void OnCollisionEnter2D(Collision2D col){
if (col.gameObject.tag == "fireHOSE") {
col.gameObject.SetActive(false);
score += 2;
guiScore.text = "Score: " + score;
Debug.Log("collided");
}if (col.gameObject.tag == "hydrant") {
guiScore.text = "Score: " + score;
}
}
the first collision working but the second doesnt. i alligned the objects so that they are in the same axis so they would collide. i used box collider and i give the player a rigidbody. i need help. please and thanks
Your syntax seems to be good. Probably something else is not set correctly.
check: tags, layers, if colliders are triggers, if colliders are all primitives(no mesh colliders), if your moving object is very fast try to put collision detection to continuous dynamic, and that can depend on the way you are moving your gamobjects too.
Answer by RLin · Jun 26, 2015 at 10:53 PM
foreach(contactpoint c in col.contacts){
// put your if statements here, with col changed to c
}
Your answer
Follow this Question
Related Questions
Why doesn't this script work?? Please help.. 1 Answer
How do I stop a timer with OnTriggerEnter()? 0 Answers
dont instantiate clones 1 Answer