Here is a simple camera jitter method, which is recorded for easy reference.
Public class camerashake: monobehaviour {// transform of the jitter target (if no reference is added, how can it be transform of the current object by default) Public transform camtransform; // duration of continuous jitter public float shake = 0f; // jitter amplitude (amplitude)
// The larger the amplitude, the worse the jitter. Public float shakeamount = 0.7f; public float decreasefactor = 1.0f; vector3 originalpos; void awake () {If (camtransform = NULL) {camtransform = getcomponent (typeof (Transform) as transform ;}} void onenable () {originalpos = camtransform. localposition;} void Update () {If (shake> 0) {camtransform. localposition = originalpos + random. insideunitsphere * shakeamount; shake-= time. deltatime * decreasefactor;} else {shake = 0f; camtransform. localposition = originalpos ;}}}
It can actually shake any object.
Simple implementation of the effect of shaking screen (shaking camera) in unity3d