PixelSphinx/Assets/Scripts/CameraShake.cs
Jean-Sébastien Gervais 412af97ba8 Camera shakeable
2016-04-09 16:15:55 -04:00

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;
}
}
}