Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ShakeCamera : MonoBehaviour
- {
- public static ShakeCamera Instance;
- public float time = 0.1f;
- public float amp = 0.25f;
- private bool shaking;
- private Vector3 pos;
- void Start ()
- {
- Instance = this;
- pos = transform.localPosition;
- }
- void Update ()
- {
- if(shaking)
- {
- transform.localPosition = pos + Random.insideUnitSphere * amp;
- }
- }
- public void Shake(float Time, float Amp)
- {
- time = Time;
- amp = Amp;
- shaking = true;
- Invoke("Stop", time);
- }
- void Stop()
- {
- shaking = false;
- transform.localPosition = pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement