Advertisement
Guest User

Unity: Camera Shake

a guest
Jul 31st, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ShakeCamera : MonoBehaviour
  5. {
  6.  
  7.     public static ShakeCamera Instance;
  8.     public float time = 0.1f;
  9.     public float amp = 0.25f;
  10.  
  11.     private bool shaking;
  12.     private Vector3 pos;
  13.  
  14.     void Start ()
  15.     {
  16.         Instance = this;
  17.         pos = transform.localPosition;
  18.     }
  19.    
  20.     void Update ()
  21.     {
  22.         if(shaking)
  23.         {
  24.             transform.localPosition = pos + Random.insideUnitSphere * amp;
  25.         }
  26.     }
  27.  
  28.     public void Shake(float Time, float Amp)
  29.     {
  30.         time = Time;
  31.         amp = Amp;
  32.         shaking = true;
  33.         Invoke("Stop", time);
  34.     }
  35.  
  36.     void Stop()
  37.     {
  38.         shaking = false;
  39.         transform.localPosition = pos;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement