- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
- 纳金币
- 53488
- 精华
- 316
|
获取动画时间的名称,在旧版动画(Animation)中使用如下代码:
using UnityEngine;
using System.Collections;
publicclass ScreenShake : MonoBehaviour
{
privatefloat shakeTime = 0.0f;
privatefloat fps= 20.0f;
privatefloat frameTime =0.0f;
privatefloat shakeDelta =0.005f;
public Camera cam ;
publicstaticbool isshakeCamera =false;
// Use this for initializationvoid Start ()
{
shakeTime = 2.0f;
fps= 20.0f;
frameTime =0.03f;
shakeDelta =0.005f;
//isshakeCamera=true;
}
// Update is called once per framevoid Update ()
{
if (isshakeCamera)
{
if(shakeTime > 0)
{
shakeTime -= Time.deltaTime;
if(shakeTime <= 0)
{
cam.rect = new Rect(0.0f,0.0f,1.0f,1.0f);
isshakeCamera =false;
shakeTime = 1.0f;
fps= 20.0f;
frameTime =0.03f;
shakeDelta =0.005f;
}
else
{
frameTime += Time.deltaTime;
if(frameTime > 1.0 / fps)
{
frameTime = 0;
cam.rect = new Rect(shakeDelta * ( -1.0f + 2.0f * Random.value),shakeDelta * ( -1.0f + 2.0f * Random.value), 1.0f, 1.0f);
}
}
}
}
}
}
新版动画(Animator)使用如下代码:
AnimatorClipInfo[] animInfo = anim.GetCurrentAnimatorClipInfo(0);
foreach (var item in animInfo)
{
print(item.clip.name);
}
|
|