Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class AnimalHunger : MonoBehaviour
- {
- public Slider hungerSlider;
- public int amountToBeFed;
- private int currentAmountFed = 0;
- private GameManager gameManager;
- void Start()
- {
- hungerSlider.maxValue = amountToBeFed;
- hungerSlider.value = 0;
- hungerSlider.fillRect.gameObject.SetActive(false);
- gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
- }
- public void FeedAnimal(int amount)
- {
- currentAmountFed += amount;
- hungerSlider.fillRect.gameObject.SetActive(true);
- hungerSlider.value = currentAmountFed;
- if(currentAmountFed >= amountToBeFed)
- {
- gameManager.AddScore(amountToBeFed);
- Destroy(gameObject, 0.1f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement