Advertisement
SvOzMaS

WeaponPick

Oct 28th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class WeaponPick : MonoBehaviour {
  5.  
  6.     public GameObject weapon;               // Reference to the weapon that is going to disappear
  7.     [Range (0, 360)]                        // Limit for the range of degreesPerSecond variable
  8.     public int degreesPerSecond;            // The degrees that the weapon will rotate per second
  9.     public AudioClip[] weaponPickClips;     // Array of clips for when the player pick a weapon.
  10.  
  11.     // Update is called once per frame
  12.     void Update() {
  13.         //rotates x degrees per second around y axis
  14.         transform.Rotate(0, degreesPerSecond * Time.deltaTime, 0 );
  15.     }
  16.  
  17.     // Event that is triggered when an object enters the collision box
  18.     // The object that enters the collision is the one passed as the "other"
  19.     // This event is only triggered once
  20.     void OnTriggerEnter(Collider other) {
  21.         // Find the Player by using the tag "Player"
  22.         // Gets the Component PlayerWeaponController on the Player
  23.         // Calls the public method to equip the weapon
  24.         if (other.tag == "Player") {
  25.             other.GetComponent<PlayerWeaponController>().EquipWeapon();
  26.             playWeaponPickClip();
  27.         }
  28.        
  29.         Destroy(weapon); // Destroy the weapon we just catch
  30.     }
  31.  
  32.     public void playWeaponPickClip() {
  33.         // Play a random jump audio clip, if there is any
  34.         if (weaponPickClips.Length > 0) {
  35.             int i = Random.Range(0, weaponPickClips.Length);
  36.            AudioSource.PlayClipAtPoint(weaponPickClips[i], transform.position);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement