-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShaker.cs
More file actions
43 lines (37 loc) · 989 Bytes
/
Shaker.cs
File metadata and controls
43 lines (37 loc) · 989 Bytes
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
using System;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Agricosmic.Utilities
{
public class Shaker : MonoBehaviour
{
[SerializeField] private float _intensity = 1f;
private float _shakeTime = 0f;
private Vector3 _center;
private void Start()
{
_center = transform.position;
}
private void Update()
{
if (_shakeTime > 0f)
{
_shakeTime -= Time.unscaledDeltaTime;
var offset = Random.insideUnitCircle * _shakeTime * _intensity;
transform.position = (Vector2)_center + offset;
}
else
{
transform.position = Vector3.Lerp(transform.position, _center, 0.2f);
}
}
public void Shake(float time)
{
_shakeTime = time;
}
public void StopShake()
{
_shakeTime = 0f;
}
}
}