forked from Angus-Fan/TurnBasedStrategyGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamShakeScript.cs
36 lines (27 loc) · 1.14 KB
/
camShakeScript.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camShakeScript : MonoBehaviour
{
public IEnumerator camShake(float duration,float camShakeStrength,Vector3 direction)
{
float updatedShakeStrength = camShakeStrength;
if (camShakeStrength > 10)
{
camShakeStrength = 10;
}
Vector3 originalPos = transform.position;
Vector3 endPoint = new Vector3(direction.x, 0, direction.z)*(camShakeStrength/2);
float timePassed = 0f;
while (timePassed < duration)
{
float xPos = Random.Range(-.1f, .1f)*camShakeStrength;
float zPos = Random.Range(-.1f, .1f)*camShakeStrength;
Vector3 newPos = new Vector3(transform.position.x + xPos, transform.position.y, transform.position.z + zPos);
//Vector3 newPos = endPoint + originalPos;
transform.position = Vector3.Lerp(transform.position,newPos,0.15f);
timePassed += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
}
}