Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class WeaponRecoil : MonoBehaviour {
  5.  
  6.     private float recoil = 0f;
  7.     private float maxRecoil_x = -20f;
  8.     private float maxRecoil_y = 20f;
  9.     private float recoilSpeed = 2f;
  10.  
  11.     public void StartRecoil(float recoilParam, float maxRecoil_xParam, float recoilSpeedParam) {
  12.         recoil = recoilParam;
  13.         maxRecoil_x = maxRecoil_xParam;
  14.         recoilSpeed = recoilSpeedParam;
  15.         maxRecoil_y = Random.Range (0, maxRecoil_xParam);
  16.     }
  17.  
  18.     void recoiling() {
  19.         if (recoil > 0f) {
  20.             Quaternion maxRecoil = Quaternion.Euler (-maxRecoil_x, 0f, 0f);
  21.             transform.localRotation = Quaternion.Slerp (transform.localRotation, maxRecoil, Time.deltaTime * recoilSpeed/6);
  22.             recoil -= Time.deltaTime;
  23.         } else {
  24.             recoil = 0f;
  25.             //transform.localRotation = Quaternion.Slerp (transform.localRotation, Quaternion.identity, Time.deltaTime * recoilSpeed / 2);
  26.         }
  27.     }
  28.  
  29.     void Update() {
  30.         recoiling ();
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement