Skip to content

Instantly share code, notes, and snippets.

@rbreve
Created July 3, 2015 21:06
Show Gist options
  • Save rbreve/932889252d1d9333401e to your computer and use it in GitHub Desktop.
Save rbreve/932889252d1d9333401e to your computer and use it in GitHub Desktop.
Simple camera shake script for Unity3d
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