mirror of
https://github.com/ConjureETS/PixelSphinx.git
synced 2026-03-24 10:30:59 +00:00
37 lines
854 B
C#
37 lines
854 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class CameraShake : MonoBehaviour
|
|
{
|
|
|
|
public float shakeTimeAmount = 0.0f;
|
|
public float shakeAmount = 0.7f;
|
|
public float decreaseFactor = 1.0f;
|
|
|
|
private Camera camera;
|
|
|
|
// Use this for initialization
|
|
public void Start ()
|
|
{
|
|
camera = gameObject.GetComponent<Camera>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
public void FixedUpdate () {
|
|
if (shakeTimeAmount > 0)
|
|
{
|
|
var tempShakePosition = camera.transform.localPosition = Random.insideUnitSphere * shakeAmount;
|
|
tempShakePosition.z = -10f; // lock z from shaking...
|
|
camera.transform.localPosition = tempShakePosition; //
|
|
shakeTimeAmount -= Time.deltaTime * decreaseFactor;
|
|
}
|
|
else
|
|
{
|
|
shakeTimeAmount = 0.0f;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|