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);
}
}
}
}
}
}
打赏
扫一扫,请博主喝杯咖啡~