This commit is contained in:
Gerard Gascón 2025-04-24 14:23:29 +02:00
commit bd5b1556ff
269 changed files with 6249829 additions and 0 deletions

View file

@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraShake : MonoBehaviour{
float shakeAmount = 0;
Vector3 startPos;
public void Shake(float amt, float length){
shakeAmount = amt;
startPos = transform.localPosition;
InvokeRepeating("DoShake", 0, 0.01f);
Invoke("StopShake", length);
}
void DoShake(){
if (shakeAmount > 0){
Vector3 camPos = transform.position;
float offsetX = Random.value * shakeAmount * 2 - shakeAmount;
float offsetY = Random.value * shakeAmount * 2 - shakeAmount;
camPos.x += offsetX;
camPos.y += offsetY;
transform.position = camPos;
}
}
void StopShake(){
CancelInvoke("DoShake");
transform.localPosition = startPos;
}
}