I have a script called Hitbox attached to a GameObject called “PlayerWeapon”. Here’s the script:
public var damage:int; public var attackTime:float; var StruckObjects:Array; function OnTriggerEnter(other:Collider) { if (other.gameObject.tag == "Foe") { var tScript = other.GetComponent("Foe"); tScript.TakeDamage(damage); } }
It’s just supposed to check if something you collided with is tagged “Foe”, and if it is, call TakeDamage on that foe. The ‘damage’ variable is set every time you attack, and attacking is part of a completely different script.
The GameObject called PlayerWeapon has a collider marked IsTrigger that’s like, three times as wide as it and the same height…
PlayerWeapon is a parent of a little model of a sword I made (just two cylinders…).
I have a script that makes you swing the weapon in front of you, and it works fine. When I’m attacking and I check the Scene view, the collider of PlayerWeapon moves along with the sword just fine and it seems to be colliding with things, but nothing happens.
I’ve put a ‘print’ function in the TriggerEnter and also one inside the If, but neither of them print when I swing the weapon at cubes and such. I tried adding a Rigidbody to the cubes that I’m swinging at, but it still doesn’t pick anything up.
I have a Hitbox script component added to PlayerWeapon and the collider is a trigger…
What am I missing? Why isn’t either print going off?
I thought I read something about requiring a rigidbody on either colliding object for collisions to work, but I thought it was only for collisions, not trigger collisions. Besides, I’ve added rigidbodies to the cubes and it doesn’t work.
Any help would be appreciated,
Thanks!