Chest.cs 692 B

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. using System.Collections;
  3. public class Chest : MonoBehaviour {
  4. public Transform player;
  5. public float minDistance;
  6. public ParticleSystem ChestParticles;
  7. private bool opened = false;
  8. void Start()
  9. {
  10. if (ChestParticles) {
  11. Instantiate (ChestParticles, this.transform.position, this.transform.rotation);
  12. }
  13. }
  14. void OnMouseDown()
  15. {
  16. if (player) {
  17. float dist = Vector3.Distance (player.position, transform.position);
  18. if (dist < minDistance && opened == false) {
  19. GetComponent<Animation>().Play ("Opening");
  20. GetComponent<AudioSource>().Play();
  21. opened = true;
  22. }
  23. }
  24. else {
  25. Debug.Log ("assing a Player to open the chest");
  26. }
  27. }
  28. }