Script in animations

Hello everyone,
I’m looking for a way to drive scripts during an animation. The purpose is to use the animator to graphically design a state-machine which doesn’t move anything in the scene. The way I would use is to implement a launch, update and close methods called during an animation and link it into the animator, and then, use the animator typical transitions to go from a script to another.
Is there a way to do this? Or maybe something similar?
Thank you!
NB: I’m coding in C# under Unity 4.6 beta.

If I understand your question correctly this is a new feature in 5.0 called StateMachineBehaviour(SMB).

You basically put a SMB on a statemachine or state and every time that this statemachine or state is evaluated your script is called. Here what it look like

public class MyAttackBehaviour : StateMachineBehaviour {

     // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
   
    }

    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
   
    }

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    
    }

    // OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
    override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    
    }

    // OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
    override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    
    }
}

This is exactly what I’m looking for!
I’ll probably buy 5.0 license soon, but for now I continue to use 4.6 beta. So I figured out another way, it doesn’t look good but it works. it uses one gameobject which check what state is running and so run right method using polymorphism. I will use this method until I get the 5.0 then.
Thank you!

make somethink’s like that’s but at this time continue scearch the best way to use it

using UnityEngine;
using System.Collections;
public class start : StateMachineBehaviour {
public Basic_anim action;
public void Start(){

}
// OnStateEnter is called before OnStateEnter is called on any state inside this state machine
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (action == null )
action = animator.gameObject.GetComponent<Basic_anim>();

action.OnStateEnter (animator,stateInfo,layerIndex);
}
// OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (action == null )
action = animator.gameObject.GetComponent<Basic_anim>();
action.OnStateUpdate (animator,stateInfo,layerIndex);
}
// OnStateExit is called before OnStateExit is called on any state inside this state machine
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (action == null )
action = animator.gameObject.GetComponent<Basic_anim>();
action.OnStateExit (animator,stateInfo,layerIndex);
}
// OnStateMove is called before OnStateMove is called on any state inside this state machine
override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (action == null )
action = animator.gameObject.GetComponent<Basic_anim>();
action.OnStateMove (animator,stateInfo,layerIndex);

}
// OnStateIK is called before OnStateIK is called on any state inside this state machine
override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (action == null )
action = animator.gameObject.GetComponent<Basic_anim>();
action.OnStateEnter (animator,stateInfo,layerIndex);
}
// OnStateMachineEnter is called when entering a statemachine via its Entry Node
override public void OnStateMachineEnter(Animator animator, int stateMachinePathHash){
if (action == null )
action = animator.gameObject.GetComponent<Basic_anim>();
action.OnStateMachineEnter (animator,stateMachinePathHash);
}
// OnStateMachineExit is called when exiting a statemachine via its Exit Node
override public void OnStateMachineExit(Animator animator, int stateMachinePathHash) {
if (action == null )
action = animator.gameObject.GetComponent<Basic_anim>();
action.OnStateMachineExit (animator,stateMachinePathHash);
}
}