Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class WeaponPick : MonoBehaviour {
- public GameObject weapon; // Reference to the weapon that is going to disappear
- [Range (0, 360)] // Limit for the range of degreesPerSecond variable
- public int degreesPerSecond; // The degrees that the weapon will rotate per second
- public AudioClip[] weaponPickClips; // Array of clips for when the player pick a weapon.
- // Update is called once per frame
- void Update() {
- //rotates x degrees per second around y axis
- transform.Rotate(0, degreesPerSecond * Time.deltaTime, 0 );
- }
- // Event that is triggered when an object enters the collision box
- // The object that enters the collision is the one passed as the "other"
- // This event is only triggered once
- void OnTriggerEnter(Collider other) {
- // Find the Player by using the tag "Player"
- // Gets the Component PlayerWeaponController on the Player
- // Calls the public method to equip the weapon
- if (other.tag == "Player") {
- other.GetComponent<PlayerWeaponController>().EquipWeapon();
- playWeaponPickClip();
- }
- Destroy(weapon); // Destroy the weapon we just catch
- }
- public void playWeaponPickClip() {
- // Play a random jump audio clip, if there is any
- if (weaponPickClips.Length > 0) {
- int i = Random.Range(0, weaponPickClips.Length);
- AudioSource.PlayClipAtPoint(weaponPickClips[i], transform.position);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement