Hello,
I am looking to create a script that will select preset animations in the inspector randomly?
Would anyone have an idea of how to write this code?
Warning !
I do not try to do this with the function “Animator” But with “Animation” in the inspector!
(The animations are already predefined and integrated in the prefabricated)
Thank you in advance for your answers
int CurrentAnimation = Random.Range(0,Animations.Count);
Animator.SetIntiger("CurrentAnimation", CurrentAnimation);
List animations;
Animation Animation;
void Start(){
Animation = GetComponent<Animation>();
CreateAnimationList();
}
void CreateAnimationList(){
animations = new List<string>();
foreach(AnimationState state in Animation){
animations.Add(state.clip.name);
}
}
void PlayRandomAnimation(){
int r = Random.Range(0, animations.Count);
PlayAnimation(r);
}
public void PlayAnimation(int id){
Animation.Play(animations[id]);
}
Hope it help you.
Thank you very much for your help, I will test the script and try to make it work!
I would like you to juice if it works or not, again thank you