- Home /
Question by
CallToAdventure · Mar 06, 2012 at 03:33 PM ·
triggertag
Collision by tag issues
It so happens I don't want a stray bullet to go through walls and activate a spawn enemy trigger - or something. So I looked into the tag solution. But I am missing something :
var someString : String;
@script AddComponentMenu("Gameplay/Trigger Message")
function OnTriggerEnter (collision : Collider) {
if (collision.gameObject.tag == "PlayerTrigger");
MessageList.Instance().AddMessage(someString);
Destroy (gameObject);
}
The PlayerTrigger is a colider in the player gameObject hierarchy. The projectile has a Projectile tag itself. Yet, shooting the trigger will just, well, trigger it.
Comment
Answer by jakovd · Mar 06, 2012 at 03:52 PM
I'm a C# programmer myself but this doesn't seem right:
if (collision.gameObject.tag == "PlayerTrigger"); <--- this semicolon :)
edit: just to be clear, you should open curly brackets here and close it after the next two lines.