|
Alright this should be a fairly simple question: I have a object so when (the problem) something enters, it runs a script using OnTiggerEnter.The problem with is the fact that it runs no matter what enters. So if a stray bullet goes into it, it runs. When a enemy wonders into, it runs. I know HOW to fix it, i just don't know the syntax for it, as i am fairly new to JavaScript and Unity. Well here is the script. Also, as a bonus point, if you know about arrays, could you help me make the script better? I want to make it so i don't have to write instantiate for every single thing.
(comments are locked)
|
|
straight from the documentation:
As you can see there, the OnTriggerEnter function accepts a collider as parameter. Basically, it tells you exactly which object entered the trigger. You can check "other" and see whether it is the player or a bullet or whatever which entered your trigger. Possibly check for the tag of your entering collider and only trigger something when the tag of your entering collider is e.g. "player" again from the documentation:
Combine the two script examples and you should be all set That should result in a statement like such in your OnTriggerEnter function:
(comments are locked)
|

I kicked out two of your tags as they were unrelated to the actual problem. Please correct the typo in your question title so that other people can find your question more easily. Thanks!