- Home /
Trigger Animation Controller Parameter With Collider
Hello I need my ai to activate an animation controller when it hits a box collider (set as is trigger). But I have idea how to do this especially since the collider isn't on the ai.
Thank you
Comment
any code or screenshots to share so that we can help with the answers?
I think this problem can be solved so:
private Animator _animator;
private void Start () {
_animator = GetComponent<Animator> ();
}
private void OnCollisionEnter () {
_animator.SetBool("SomeParameterName");
}
Answer by betaFlux · Sep 19, 2014 at 03:17 PM
Do you want to enable the animator component? Then just take Lex_87's code and replace the OnCollisionEnter function with
void OnTriggerEnter(Collider collidingObject)
{
// get a reference to your character
if(collidingObject.tag == "InsertYourTagHere") // Or collidingObject.gameObject.tag instead. I'm not sure
{
collidingObject.gameObject.GetComponent<Animator>().enabled = true;
}
}
Your answer
Follow this Question
Related Questions
Animation in Unity 4.3 0 Answers
Is it a way to get the animation object form the animator? 0 Answers
Animation component in Unity 4.3 doesn't work? 2 Answers
2D Animation does not start 1 Answer