| | | 1 | | using UnityEngine; |
| | | 2 | | using System.Collections; |
| | | 3 | | |
| | | 4 | | /** |
| | | 5 | | * This class will be used as parent for Coin and Key |
| | | 6 | | * Gives objects ability to be collected with poof and sound, also adds object rotation |
| | | 7 | | */ |
| | | 8 | | public class Collectible : MonoBehaviour { |
| | | 9 | | |
| | 285 | 10 | | protected bool _isCollected = false; |
| | 285 | 11 | | protected Vector3 _rotationVector = new Vector3(0f, 1f, 0f); |
| | | 12 | | |
| | | 13 | | // public settings |
| | | 14 | | public GameObject poof; |
| | 285 | 15 | | public float rotationSpeed = 150.0f; |
| | | 16 | | |
| | | 17 | | [Header("Sounds")] |
| | 285 | 18 | | public AudioClip collect_sound = null; |
| | | 19 | | |
| | | 20 | | protected void Update() |
| | 804850 | 21 | | { |
| | | 22 | | // rotate object |
| | 804850 | 23 | | gameObject.transform.Rotate(_rotationVector * rotationSpeed * Time.deltaTime); |
| | 804850 | 24 | | } |
| | | 25 | | |
| | | 26 | | public void Collect() |
| | 193 | 27 | | { |
| | | 28 | | // Create poof |
| | 193 | 29 | | GameObject poofInstance = (GameObject)Object.Instantiate(poof, gameObject.transform.position, poof.transform.rot |
| | | 30 | | |
| | | 31 | | // Play sounds using poof's audio source (because our original object will be destroyed) |
| | 193 | 32 | | AudioSource poofSound = poofInstance.GetComponent<AudioSource>(); |
| | 193 | 33 | | poofSound.clip = collect_sound; |
| | 193 | 34 | | poofSound.Play(); |
| | | 35 | | |
| | | 36 | | // destroy collectible |
| | 193 | 37 | | Object.Destroy(gameObject); |
| | | 38 | | |
| | | 39 | | // set collected flag |
| | 193 | 40 | | _isCollected = true; |
| | 193 | 41 | | } |
| | | 42 | | |
| | | 43 | | public bool isCollected() |
| | 0 | 44 | | { |
| | 0 | 45 | | return _isCollected; |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | // Use this for initialization |
| | 285 | 49 | | void Start () { |
| | | 50 | | |
| | 285 | 51 | | } |
| | | 52 | | |
| | | 53 | | } |