C# 如何使用AnimationEvent和SendMessageOptions.DontRequestReceiver?
但按了几次之后,我得到了以下3个例外: “太空士兵”动画片“RollSound”没有接收器!是 你缺少一个部件 “太空士兵”AnimationEvent“CantRotate”没有接收器! 您是否缺少一个组件 “太空士兵”AnimationEvent“EndRoll”没有接收器!是 你缺少一个部件 当在空间的层次中时,我会制作窗口>动画,我不能更改/编辑动画和事件。我看到一条信息: 请选择没有“优化游戏对象”的游戏对象 应用 我不知道该怎么办 然后我尝试用AnimationEvent将这两行代码添加到脚本中,但没有解决问题。如何解决这3个异常C# 如何使用AnimationEvent和SendMessageOptions.DontRequestReceiver?,c#,unity3d,unity5,C#,Unity3d,Unity5,但按了几次之后,我得到了以下3个例外: “太空士兵”动画片“RollSound”没有接收器!是 你缺少一个部件 “太空士兵”AnimationEvent“CantRotate”没有接收器! 您是否缺少一个组件 “太空士兵”AnimationEvent“EndRoll”没有接收器!是 你缺少一个部件 当在空间的层次中时,我会制作窗口>动画,我不能更改/编辑动画和事件。我看到一条信息: 请选择没有“优化游戏对象”的游戏对象 应用 我不知道该怎么办 然后我尝试用AnimationEvent将这两行代码
我的主要目标是在每次按A键时播放动画师的所有状态。解决方案是将此异常作为方法添加到脚本中。 它们可以是空的,但它们应该在那里
AnimationEvent ae = new AnimationEvent();
ae.messageOptions = SendMessageOptions.DontRequireReceiver;
如果你想在这个方法中加入一些东西,比如在RollSound中放置一些音频剪辑,你也可以稍后再使用
但是,这个想法是,这个动画有事件,而不是开始混乱的事件和动画只是为了添加这个方法
AnimationEvent ae = new AnimationEvent();
ae.messageOptions = SendMessageOptions.DontRequireReceiver;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Animations;
using UnityEngine;
public class SwitchAnimations : MonoBehaviour
{
private Animator animator;
private static UnityEditor.Animations.AnimatorController controller;
private AnimatorState[] states;
// Use this for initialization
void Start()
{
animator = GetComponent<Animator>();
states = GetStateNames(animator);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
StartCoroutine(QueueAnim(states));
}
}
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();
}
IEnumerator QueueAnim(params AnimatorState[] anim)
{
int index = 0;
while (index < anim.Length)
{
if (index == anim.Length)
index = 0;
animator.Play(anim[index].name);
AnimatorStateInfo si = animator.GetCurrentAnimatorStateInfo(index);
yield return new WaitForSeconds(5);
index++;
}
}
private void RollSound()
{
}
private void CantRotate()
{
}
private void EndRoll()
{
}
private void EndPickup()
{
}
}