Created
July 3, 2015 21:06
-
-
Save rbreve/932889252d1d9333401e to your computer and use it in GitHub Desktop.
Simple camera shake script for Unity3d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CameraShake : MonoBehaviour { | |
Camera cam; | |
public float shakeTime=0.2f; | |
float timeStop=0; | |
float shakeAmount=0.3f; | |
Vector3 originPosition; | |
void Start () { | |
cam = Camera.main; | |
} | |
public void shakeNow(){ | |
originPosition = cam.transform.position; | |
timeStop = Time.time + shakeTime; | |
} | |
// Update is called once per frame | |
void Update () { | |
if(Time.time < timeStop){ | |
cam.transform.localPosition = originPosition + Random.insideUnitSphere * shakeAmount; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment