public var animatie : AnimationClip;
enum AIState {None, Proximity}
var switchKind = AIState.None;
function Update(){
if{switchKind == AIState.Proximity){
animation.Play(the one in the variable animatie);
}
So what I want is that if a Animation file is put in the variable slot in the inspector, the animation get played when the dropdown menu is on Proximity. I tried just typing in the name of the veriable and also qouted it ("animatie"). But these dont seem to work. Any ideas how to get it work?
It doesn't quite work like you are trying to make it.
Firstly, the object must have an animation component for animations to work. This is under Component/Miscellaneous.
Secondly, animation will play animations in the animations array. To add a clip, you can change the array in the inspector or through script, you can add animations to the array with Animation.AddClip or remove them with Animation.RemoveClip.
Lastly all of the functions that play animations (Animation.Play or Animation.Blend, etc.) take in a string specifying the name the Animation Clip in the Animations array. (Each AnimationClip has a name property).
To do what you describe, you would add the animation to the animation component and then tell it to play the animation with the specified name.
//The animation in the Animations array in the inspector
public var animationName : String;
enum AIState { None, Proximity }
var state : AIState = AIState.None;
function Update() {
if(state == AIState.Proximity) animation.Play(animationName);
}
@script RequireComponent(Animation)
Or you would add the animation clip to the array at runtime, but this is more work than just adding it to the inspector:
public var clip : AnimationClip;
enum AIState { None, Proximity }
var state : AIState = AIState.None;
function Start() {
animation.AddClip(clip, clip.name);
}
function Update() {
if(state == AIState.Proximity) animation.Play(clip.name);
}
@script RequireComponent(Animation)