Merge branch 'main' of https://gitea.deprived.dev/Sveskejuice/ColorDefense
This commit is contained in:
commit
e9cb1330bb
|
@ -4,6 +4,8 @@ using System.Collections;
|
||||||
|
|
||||||
public class CameraController : MonoBehaviour
|
public class CameraController : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public static CameraController instance;
|
||||||
|
|
||||||
[SerializeField] private GameObject cam;
|
[SerializeField] private GameObject cam;
|
||||||
|
|
||||||
public float scrollSpeed = 2.5f;
|
public float scrollSpeed = 2.5f;
|
||||||
|
@ -15,8 +17,17 @@ public class CameraController : MonoBehaviour
|
||||||
|
|
||||||
private float timer;
|
private float timer;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
if (instance != this)
|
||||||
|
instance = this;
|
||||||
|
|
||||||
defaultMaxSpeed *= 0;
|
defaultMaxSpeed *= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,4 +67,28 @@ public class CameraController : MonoBehaviour
|
||||||
if (!Input.GetMouseButton(1))
|
if (!Input.GetMouseButton(1))
|
||||||
defaultMaxSpeed = Vector2.LerpUnclamped(defaultMaxSpeed, Vector2.zero, curve.Evaluate(evalTime));
|
defaultMaxSpeed = Vector2.LerpUnclamped(defaultMaxSpeed, Vector2.zero, curve.Evaluate(evalTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShakeCamera(float intensity, float duration)
|
||||||
|
{
|
||||||
|
StartCoroutine(DoShake(intensity, duration));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator DoShake(float intensity, float duration)
|
||||||
|
{
|
||||||
|
Vector3 originalOffset = cam.GetComponent<CinemachineCameraOffset>().m_Offset;
|
||||||
|
float elapsed = 0.0f;
|
||||||
|
|
||||||
|
while (elapsed < duration)
|
||||||
|
{
|
||||||
|
float x = Random.Range(-1f, 1f) * intensity;
|
||||||
|
float y = Random.Range(-1f, 1f) * intensity;
|
||||||
|
|
||||||
|
cam.GetComponent<CinemachineCameraOffset>().m_Offset = new Vector3(x, y, originalOffset.z);
|
||||||
|
|
||||||
|
elapsed += Time.deltaTime;
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
cam.GetComponent<CinemachineCameraOffset>().m_Offset = originalOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue