1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| using UnityEngine;
using System.Collections;
public classShakeCamera : MonoBehaviour
{
// 震动标志位
privateboolisshakeCamera = false;
// 震动幅度
publicfloatshakeLevel = 3f;
// 震动时间
publicfloatsetShakeTime = 0.2f;
// 震动的FPS
publicfloatshakeFps = 45f;
privatefloatfps;
privatefloatshakeTime = 0.0f;
privatefloatframeTime = 0.0f;
privatefloatshakeDelta = 0.005f;
privateCamera selfCamera;
void Awake()
{
selfCamera = GetComponent<Camera>();
}
// Use this for initialization
void Start()
{
shakeTime = setShakeTime;
fps = shakeFps;
frameTime = 0.03f;
shakeDelta = 0.005f;
}
// Update is called once per frame
void Update()
{
if (isshakeCamera)
{
if (shakeTime > 0)
{
shakeTime -= Time.deltaTime;
if (shakeTime <= 0)
{
selfCamera.rect = newRect(0.0f, 0.0f, 1.0f, 1.0f);
isshakeCamera = false;
shakeTime = setShakeTime;
fps = shakeFps;
frameTime = 0.03f;
shakeDelta = 0.005f;
}
else
{
frameTime += Time.deltaTime;
if (frameTime > 1.0 / fps)
{
frameTime = 0;
selfCamera.rect = newRect(shakeDelta * (-1.0f + shakeLevel * Random.value), shakeDelta * (-1.0f + shakeLevel * Random.value), 1.0f, 1.0f);
}
}
}
}
}
publicvoidshake()
{
isshakeCamera = true;
}
}
|