- Home /
Trigger door animation with external trigger
I've been looking for nearly a week now and i cannot find a single thing that works. I am horrible at scripting, i can read/understand it fine, and correct errors no problem, creating code from scratch however is completely over my head, i don't even know how to start.
All i need is for the door animation(that i created in unity already) to be triggered when i pick up a rigidbody(already got that part running fine) and drop it in a the trigger area. That's it, seems simple enough yet i can't get it to work after 6 days of trying, getting really discouraged here :/
Javascript is preferred but at this point i'll take anything as long as it works
Answer by Loius · Nov 28, 2012 at 10:12 PM
class Triggerer extends MonoBehaviour {
}
...
class Triggerable extends MonoBehaviour {
var targetAnimator : Animation;
var targetAnimation : String;
function Start() {
if ( !collider ) Debug.LogError("Triggerable has no collider");
}
function OnTriggerEnter( other : Collider ) {
if ( other.GetComponent(Triggerer) ) {
targetAnimator.Play(targetAnimation);
}
}
}
Drop a Triggerer in a Triggerable trigger zone and tada. The triggerable needs to have an isTrigger collider, and the Triggerer needs a rigidbody and a collider.
Your answer
Follow this Question
Related Questions
Triggering door animation with collider 2 Answers
Activating One Part of An Animation 2 Answers
Unity3D AI using animations 1 Answer
A node in a childnode? 1 Answer
my animation script does not work 0 Answers