using UnityEngine;
using System.Collections;
public class FbxTest : MonoBehaviour
{
public Animator animator;
public Animation animation;
public ParticleSystem ps;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
//方法1
string aniName = GetCurrentPlayingAnimationClip(animation);
if (animation[aniName].speed > 0)
{
animation[aniName].speed = 0;
ps.Pause();
}
else
{
animation[aniName].speed = 1;
ps.Play();
}
//方法2
if (null != animator)
{
AnimationInfo[] infs = animator.GetCurrentAnimationClipState(0);
foreach (AnimationInfo info in infs)
{
if (animator.speed > 0)
{
Debug.Log("animator.speed = 0;");
animator.speed = 0;
ps.Pause();
}
else
{
Debug.Log("animator.speed = 1;");
animator.speed = 1;
ps.Play();
}
}
}
}
}
public string GetCurrentPlayingAnimationClip(Animation go)
{
if (go == null)
{
return string.Empty;
}
foreach (AnimationState anim in go)
{
if (go.IsPlaying(anim.name))
{
return anim.name;
}
}
return string.Empty;
}
}