-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTreeTask.cs
More file actions
41 lines (36 loc) · 1.02 KB
/
TreeTask.cs
File metadata and controls
41 lines (36 loc) · 1.02 KB
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 System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TreeTask : MonoBehaviour
{
public bool playerInContact;
public GameObject Farmer;
private GameObject Player;
public GameObject Tree;
// Start is called before the first frame update
void Start()
{
Player = GameObject.Find("Player");
Farmer = GameObject.Find("Farmer");
}
// Update is called once per frame
void Update()
{
if (playerInContact == true && Input.GetKeyDown(KeyCode.Space) && Player.GetComponent<PlayerScript>().hasSeed == true)
{
Tree.SetActive(true);
Farmer.GetComponent<Farmer>().TreesPlanted += 1;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Player")
{
playerInContact = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
playerInContact = false;
}
}