-
Notifications
You must be signed in to change notification settings - Fork 0
/
Apple.cs
35 lines (27 loc) · 768 Bytes
/
Apple.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Apple : MonoBehaviour
{
private SpriteRenderer sr;
private CircleCollider2D circle;
public GameObject collected;
public int score;
void Start()
{
sr = GetComponent<SpriteRenderer>();
circle = GetComponent<CircleCollider2D>();
}
private void OnTriggerEnter2D(Collider2D collider)
{
if(collider.gameObject.tag == "Player")
{
sr.enabled = false;
circle.enabled = false;
collected.SetActive(true);
GameController.instance.totalScore += score;
GameController.instance.UpdateScoreText();
Destroy(gameObject, 0.25f);
}
}
}