U3DC.COM | 优三帝研究院

Menu

震屏效果

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);
}
}
}
}
}
}
打赏
— 于 共写了764个字
— 文内使用到的标签:

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据