- Home /
Trigger enter not working
hey everyone collider for this trigger isn't working, odd, because it works when my bullets hit but not the missiles everything it set up with collides triggers and rigedbodies. I have reset unity, and everything is on the same layer should be really simple but not liking me.
everything is on the same layer, all the physics are set to defaults, I restarted unity, not sure what's happening, done this hundreds of times, its a simple trigger check.
if (other.gameObject.tag == "MissileT1")
{
Health -= 10;
Destroy(other.gameObject);
if (Health < 0)
{
if (other.gameObject.tag == "MissileT1")
{
PlayerScoreScoreCS.PlayerScore += ScoretoGive;
}
if (Fighter == true)
{
PlayerScoreScoreCS.FightersKilled += 1;
}
}
}
Answer by SurreyMuso · Jun 04 at 03:11 PM
Couple of things...
I assume this is 3D? Otherwise, you'll need OnTriggerEnter2d. Can't count the number of times I've used the 3D version by mistake when creating a 2D game :o)
You are testing for other.gameObject.tag twice. The second time is after you have destroyed other.gameObject. That doesn't look right to me.
yup I think that was it, I made it simpler and it worked haha
if (other.gameObject.tag == "MissileT1")
{
Health -= 10;
Destroy(other.gameObject);
}
Your answer

Follow this Question
Related Questions
Internal collisions 1 Answer
Colliding with trees using mesh colliders 1 Answer
PlayerObject falls through floor after adding Animations 2 Answers
Invisible collider glitch 2 Answers