Newbie mecanim question

I’ve attached an Animator Controller to my character. Inside the Animator Controller I’ve made the States I need and attached the animation clips - so far everything is fine.

My animations clips needs to be triggered by events in the game (ex: characterWasHit : boolean) so I need to write a script that trigger the variables in my Animator controller, and this brings me to my question: where do I attach the script that “talks” with the Animator Controller? … and, can someone point me to a very simple Animator Controller script that JUST sets a boolean value inside the Animator Controller?

Any help will be greatly apprecaited!!

Thanks
Jeppe

I figured it out - or at least I came to a solution that works

  1. to answer my own question: the script that “talks” with the Animator Controller needs to be attached to the same object the Animator Controller is attached to.
  2. the specific syntax for setting a boolean inside the Animator is: animator.SetBool(“variable”, true/false);
  3. here is a very simple script creating a function to set a boolean inside an Animator Controller:

using UnityEngine;

using System.Collections;

[RequireComponent(typeof(Animator))]

public class laserCTRL : MonoBehaviour {

protected Animator animator;

void Start () 
{
	animator = GetComponent<Animator>();
}

public void fireLaser () 
{

	animator.SetBool("laser", true);

}

}

I hope this was helpful

Cheers
Jeppe

I’ll go one step further and maybe provide some information you didn’t know.

Animation states (idle, walking, running) are controlled through parameters inside the animator itself. You create the parameters you want (IsIdle, IsWalking, IsRunning) and turn them on/off inside of a script attached to the object in question (AI Enemy for instance). You already appear to have figured out the basic syntax

IsWalking = true;
anim.SetBool ("IsWalking", IsWalking);

Check out the Unity docs on Animation Parameters