-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestroyOfColision_2.cs
More file actions
41 lines (32 loc) · 920 Bytes
/
Copy pathDestroyOfColision_2.cs
File metadata and controls
41 lines (32 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using UnityEngine;
using UnityEngine.UI;
public class DestroyOfColision_2 : MonoBehaviour
{
private static int score = 0;
public Slider hungerSlider;
public int foodToFill = 5;
private int currentFood = 0;
void Start()
{
hungerSlider.maxValue = foodToFill;
hungerSlider.value = 0;
hungerSlider.gameObject.SetActive(true);
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("GameController"))
{
currentFood++;
hungerSlider.value = currentFood;
Destroy(other.gameObject);
}
if (currentFood >= foodToFill)
{
score++;
Debug.Log("Your score is: " + score);
hungerSlider.gameObject.SetActive(false);
Destroy(gameObject);
Destroy(other.gameObject);
}
}
}