Skip to content

Commit 5946d76

Browse files
feat: add Camera class to implement shake effect
1 parent b022ec7 commit 5946d76

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

project/Assets/Source/Camera.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using UnityEngine;
2+
3+
public class Camera : MonoBehaviour
4+
{
5+
float shake = 0f;
6+
Vector3 originalPosition;
7+
8+
void Start()
9+
{
10+
originalPosition = transform.localPosition;
11+
}
12+
13+
void Update()
14+
{
15+
if (shake > 0)
16+
{
17+
transform.localPosition = originalPosition + Random.insideUnitSphere * shake;
18+
shake -= Time.deltaTime * 0.5f;
19+
}
20+
else
21+
{
22+
transform.localPosition = originalPosition;
23+
}
24+
}
25+
26+
public void Shake(float amount)
27+
{
28+
shake += amount;
29+
}
30+
}

project/Assets/Source/Camera.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)