init
This commit is contained in:
commit
16da8e4dde
333 changed files with 109229 additions and 0 deletions
32
Assets/Scripts/CameraShake.cs
Normal file
32
Assets/Scripts/CameraShake.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraShake : MonoBehaviour{
|
||||
|
||||
float shakeAmount = 0;
|
||||
|
||||
public void Shake(float amt, float length){
|
||||
shakeAmount = amt;
|
||||
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(nameof(DoShake));
|
||||
transform.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue