summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/CameraController.cs
blob: a95b27be47b9b15985c2ad156440b897fb4b7583 (plain)
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
using System.Collections;
using UnityEngine;

public class CameraController : MonoBehaviour
{
	public static CameraController instance;

	public AnimationCurve shakeCurve;

	public float shakeDuration = 1f;

	public float shakeScaleFactor = -1f;

	private Camera targetCamera;

	private float initialScale;

	private bool initialized;

	private void Awake()
	{
		if (instance != null)
		{
			Debug.LogWarning("More than one camera controller in the scene.");
		}
		instance = this;
	}

	private void Start()
	{
		targetCamera = Camera.main;
		initialScale = targetCamera.orthographicSize;
		initialized = true;
	}

	public void ShakePunch()
	{
		if (initialized)
		{
			StopAllCoroutines();
			StartCoroutine(ExecuteShake(shakeScaleFactor, shakeDuration));
		}
	}

	private IEnumerator ExecuteShake(float scale, float duration)
	{
		float timer = 0f;
		while (timer <= duration)
		{
			timer += Time.deltaTime;
			targetCamera.orthographicSize = initialScale + shakeCurve.Evaluate(timer / duration) * scale;
			yield return null;
		}
		targetCamera.orthographicSize = initialScale;
	}
}