Skip to content

Instantly share code, notes, and snippets.

@SenpaiRar
Created May 2, 2019 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SenpaiRar/f814790eee55f9f9e0fa0f9c100f1db2 to your computer and use it in GitHub Desktop.
Save SenpaiRar/f814790eee55f9f9e0fa0f9c100f1db2 to your computer and use it in GitHub Desktop.
This script is an item script that replenishes the player's food and then deletes itself.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class FoodScript : ClickableParent {
public string Name;
public float food_Value;
public float MMinimumDistance;
private Player_Manager Master_Manager;
public AudioSource Source;
public AudioClip Clip;
void Start () {
Master_Manager = GameObject.Find("Player").GetComponent<Player_Manager>();
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;
Source.PlayOneShot(Clip);
Destroy(gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment