I am trying to get my Boss character to shoot a laser when the player enters a trigger that is attached to the boss. Right now when I enter this trigger it does nothing and I am not sure why. This is the code I have on the player right now:
function OnTriggerEnter(col:Collider)
{
if(col.gameObject.tag == "laserTrigger")
{
Debug.Log("Hitting the trigger box");
Instantiate(bossLaserBeam, transform.position + new Vector3(-11,0,0), Quaternion.Euler(90,0,0));
}
}
When you say "it does nothing", does it print out the Debug.Log statement, or does it literally do nothing at all?
haha, i just made this suggestion about 20 seconds ago and I’ll try it again…
Does your boss character have a collider attached with the “isTrigger” box ticked?
Edit: converted to answer, given further information. The collider must be attached to the same GameObject as the script with OnTriggerEnter, not on its child.
Does one of them have a rigidbody? At least one object must have a rigidbody in order for trigger events to fire. Take a look at the table at the bottom of this page: Collision Matrix. You can make it kinematic, turn off gravity and use constraints if you don’t actually want to use it but you do need it for trigger collisions.
If it’s not that, maybe check the Layer Collision Matrix in the Physics Settings and check the tags are all set up correctly?
Also might be worth noting that the trigger events will be called on the object that the trigger is actually on and the first object up in the hierarchy that has a rigidbody. So:
BossObject (Rigidbody) → TriggerObject (Trigger) = BossObject and TriggerObject events will be called.
BossObject (Rigidbody) → TriggerObject (Rigidbody, Trigger) = TriggerObject events will be called.
When you say "it does nothing", does it print out the Debug.Log statement, or does it literally do nothing at all?
– perchikIt does nothing it won't even print the Debug
– The_Black_DeathThe trigger is a child of the boss character, its attached to it.
– The_Black_DeathNo it doesn't the only thing with trigger ticked is the cube that is the trigger.
– The_Black_DeathThe script should be on the same gameobject that has the collider ticked "isTrigger"
– perchik