using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class SwitchAnimations : MonoBehaviour
{
private Animator animator;
private int index = 0;
private static UnityEditor.Animations.AnimatorController controller;
private UnityEditor.Animations.AnimatorState[] an;
// Use this for initialization
void Start()
{
animator = GetComponent<Animator>();
an = GetStateNames(animator);
AnimationEvent ae = new AnimationEvent();
ae.messageOptions = SendMessageOptions.DontRequireReceiver;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
animator.Play(an[index].name);
if (++index == an.Length)
index = 0;
}
}
private static UnityEditor.Animations.AnimatorState[] GetStateNames(Animator animator)
{
controller = animator ? animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController : null;
return controller == null ? null : controller.layers.SelectMany(l => l.stateMachine.states).Select(s => s.state).ToArray();
}
}
I tried to add this two lines:
AnimationEvent ae = new AnimationEvent();
ae.messageOptions = SendMessageOptions.DontRequireReceiver;
But still after pressing A few times i’m getting this 3 exceptions:
‘Space_Soldier_A_LOD1’ AnimationEvent ‘RollSound’ has no receiver! Are you missing a component?
‘Space_Soldier_A_LOD1’ AnimationEvent ‘CantRotate’ has no receiver! Are you missing a component?
‘Space_Soldier_A_LOD1’ AnimationEvent ‘EndRoll’ has no receiver! Are you missing a component?
And when in the Hierarchy on the Space_Soldier_A_LOD1 i make Window > Animation i can’t change/edit the animations and events i see a message: Please select a gameobject that does not have ‘Optimize Game Objects’ applied. I didn’t understand what to do.
So then i tried to add this two lines to the script with the AnimationEvent but it didn’t solve it.
How can i solve this 3 exceptions ?