I’m trying to get an object’s animation to play if a box collider trigger, which is the child of said object, gets hit by the player. Try as I might, I can’t successfully assign the parent object to my variable without using GameObject.Find, which I don’t want to use. I’ve been trying to use transform.parent.gameObject, but my console just keeps telling me that the variable is unassigned.
function OnTriggerEnter (collider : Collider)
{
var treasureChest : GameObject = transform.parent.gamObject;
treasureChest.animation.Play();
}
Here’s my code.
The objects in question are a treasure chest (the parent) with an animation which I want to play, and a child box collider, to which this trigger script is attached.