Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [System.Serializable]
- public class FoodScript : ClickableParent {
- public AudioSource Source;
- public AudioClip Clip;
- void Start () {
- //when the gameobject is created, we find the audiosource on the player so we can use that source
- Source = GameObject.Find("Player").GetComponent<AudioSource>();
- }
- public override void OnClick(Vector3 Clickposition)
- {
- Debug.Log("Clicked " + Name + ", Distance: " + Vector3.Distance(Clickposition, transform.position));
- if(Vector3.Distance(Clickposition, transform.position) <= MMinimumDistance){
- Master_Manager.current_Hunger_Level += food_Value;
- //Because we're calling Destroy right after playing the audio, we need to use an audiosource on on the gameobject
- //Otherwise, the audio would be interrupted when its destroyed
- Source.PlayOneShot(Clip);
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement