Advertisement
Guest User

Untitled

a guest
May 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [System.Serializable]
  6. public class FoodScript : ClickableParent {
  7.  
  8.  
  9. public AudioSource Source;
  10. public AudioClip Clip;
  11. void Start () {
  12. //when the gameobject is created, we find the audiosource on the player so we can use that source
  13. Source = GameObject.Find("Player").GetComponent<AudioSource>();
  14. }
  15.  
  16. public override void OnClick(Vector3 Clickposition)
  17. {
  18. Debug.Log("Clicked " + Name + ", Distance: " + Vector3.Distance(Clickposition, transform.position));
  19.  
  20. if(Vector3.Distance(Clickposition, transform.position) <= MMinimumDistance){
  21. Master_Manager.current_Hunger_Level += food_Value;
  22. //Because we're calling Destroy right after playing the audio, we need to use an audiosource on on the gameobject
  23. //Otherwise, the audio would be interrupted when its destroyed
  24. Source.PlayOneShot(Clip);
  25. Destroy(gameObject);
  26. }
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement