Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CameraShaker : MonoBehaviour
- {
- public static void AddShake(float amount)
- {
- shake += amount;
- }
- static float shake = 0;
- public static float Shake
- {
- get { return CameraShaker.shake; }
- set { CameraShaker.shake = value; }
- }
- float MaxShake = 10;
- float LinearShakeAmount = 0.066f;
- float ShakeStrength = 10;
- float lerpAmount = 1;
- float shakeBleed = 4;
- Vector3 restingPosition;
- void Start()
- {
- restingPosition = transform.position;
- }
- void Update ()
- {
- Shake -= Time.deltaTime * shakeBleed;
- Shake = Mathf.Max(Shake, 0);
- Shake = Mathf.Min(Shake, MaxShake);
- Vector3 newPos = transform.position;
- float applyShake = Mathf.Log(Shake) + Shake * LinearShakeAmount;
- if (Shake > 0)
- {
- newPos += new Vector3(
- Random.Range(-applyShake * ShakeStrength, applyShake * ShakeStrength),
- Random.Range(-applyShake * ShakeStrength, applyShake * ShakeStrength),
- 0);
- }
- transform.position = Vector3.Lerp(restingPosition, newPos,
- Time.deltaTime * Shake * lerpAmount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement