using UnityEngine; public class CameraRecoil : MonoBehaviour { public Transform yRotation; public Transform xRotation; private float counter; private float lastValue; private AnimationCurve usedCurve; private float deltaValue; private float xRecoil; private float yRecoil; private bool hasCurve; private void Start() { } private void Update() { if (hasCurve && counter < usedCurve.keys[usedCurve.length - 1].time) { float num = usedCurve.Evaluate(counter); counter += Time.deltaTime; deltaValue = num - lastValue; lastValue = num; xRotation.Rotate(Vector3.up * Time.deltaTime * xRecoil * deltaValue, Space.World); yRotation.Rotate(Vector3.right * Time.deltaTime * yRecoil * deltaValue, Space.Self); } } public void AddRecoil(Vector2 recoil, AnimationCurve curve) { counter = 0f; lastValue = curve.Evaluate(0f); usedCurve = curve; xRecoil = recoil.x * 30f; yRecoil = recoil.y * -30f; hasCurve = true; } }