有谁能告诉我,为什么我使用这个脚本时,我的触发器不工作? 这与滑块一起使用,以擦拭动画的播放。
public class AnimatorControl : MonoBehaviour
{
public Animator anim;
public Slider slider; //Assign the UI slider of your scene in this slot
//public string animatorClipName;
Animator m_Animator;
public int i;
string m_ClipName;
AnimatorClipInfo[] m_CurrentClipInfo;
float m_CurrentClipLength;
float timer;
// public int currentFrame;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
//Get them_Animator, which you attach to the GameObject you intend to animate.
m_Animator = gameObject.GetComponent<Animator>();
//Fetch the current Animation clip information for the base layer
m_CurrentClipInfo = this.m_Animator.GetCurrentAnimatorClipInfo(0);
//Access the current length of the clip
m_CurrentClipLength = m_CurrentClipInfo[0].clip.length;
//Access the Animation clip name
m_ClipName = m_CurrentClipInfo[0].clip.name;
timer = (1 / m_CurrentClipLength) / 60;
}
// Update is called once per frame
void Update()
{
int currentFrame = (int)(m_CurrentClipInfo[0].weight * (m_CurrentClipInfo[0].clip.length *
m_CurrentClipInfo[0].clip.frameRate));
int w = anim.GetCurrentAnimatorClipInfo(0).Length;
string[] clipName = new string[w];
if (Input.GetKeyDown(KeyCode.Space)) anim.SetTrigger("Next");
for (int i = 0; i < w; i += 1)
{
clipName[i] = anim.GetCurrentAnimatorClipInfo(0)[i].clip.name;
Debug.Log(clipName[i]);
string clip = clipName[i].ToString();
// anim.Play(clip, 0, slider.normalizedValue);
}
// Debug.Log(m_CurrentClipInfo[0].clip.name);
slider.normalizedValue += timer;
}
}
我在动画器中使用空格键来触发动画转换,这很有效。 anim.Play(clip, 0, slider.normalizedValue);
我的触发器将无法工作。 anim.Play(clip, 0, slider.normalizedValue);
触发器又开始工作了......
问题是你在更新循环中调用了:
// anim.Play(clip, 0, slider.normalizedValue);
从你的更新循环中调用了: 这意味着在每一帧开始时你都在调用它,所以不管你的触发器是否触发,都会在下一帧中立即调用。
anim.Play(clip, 0, slider.normalizedValue);
再次被调用。把它从更新循环中取出来,从其他地方调用它。