Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class WeaponRecoil : MonoBehaviour {
- private float recoil = 0f;
- private float maxRecoil_x = -20f;
- private float maxRecoil_y = 20f;
- private float recoilSpeed = 2f;
- public void StartRecoil(float recoilParam, float maxRecoil_xParam, float recoilSpeedParam) {
- recoil = recoilParam;
- maxRecoil_x = maxRecoil_xParam;
- recoilSpeed = recoilSpeedParam;
- maxRecoil_y = Random.Range (0, maxRecoil_xParam);
- }
- void recoiling() {
- if (recoil > 0f) {
- Quaternion maxRecoil = Quaternion.Euler (-maxRecoil_x, 0f, 0f);
- transform.localRotation = Quaternion.Slerp (transform.localRotation, maxRecoil, Time.deltaTime * recoilSpeed/6);
- recoil -= Time.deltaTime;
- } else {
- recoil = 0f;
- //transform.localRotation = Quaternion.Slerp (transform.localRotation, Quaternion.identity, Time.deltaTime * recoilSpeed / 2);
- }
- }
- void Update() {
- recoiling ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement