TentInteractoins.cs 1.84 KB
Newer Older
1
2
3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
4
using UnityEngine.UI;
5
6
7

public class TentInteractoins : MonoBehaviour {

8
    public Button interactButton;
9
    //public GameObject particleSystem;
10

11
12
13
14
15
16
17
18
19
20
    private GameObject player;
    private BoxCollider2D thisCollider;
    private ContactFilter2D filter = new ContactFilter2D();

    private bool interactable;
    // Use this for initialization
    void Start() {
        player = GameObject.FindWithTag("Player");
        thisCollider = GetComponent<BoxCollider2D>();
        filter.SetLayerMask(LayerMask.GetMask("Player"));
21
        interactButton.gameObject.SetActive(false);
22
23
24
25
    }

    // Update is called once per frame
    void Update() {
26
27
28
29
30
31
32
33
34
        if (GameManager.HasTalkedToAhava)
        {
            checkNearbyPlayers();
            if (interactable)
            {
                if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.E))
                {
                    DaytimeManager.beginPerformance();
                }
35
36
37
38
            }
        }
    }

39
    private void checkNearbyPlayers() {
40
        //CapsuleCollider2D playerCol = player.GetComponent<CapsuleCollider2D>(); //unused
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        Collider2D[] foundPlayers = new Collider2D[1];
        if (thisCollider.OverlapCollider(filter, foundPlayers) > 0) {
            if (!interactable) {
                EnterInteractable();
            }
            interactable = true;
        } else {
            if (interactable) {
                ExitInteractable();
            }
            interactable = false;
        }
    }

    void EnterInteractable() {
56
        interactButton.gameObject.SetActive(true);
57
        //particleSystem.SetActive(true);
58
59
60
    }

    void ExitInteractable() {
61
        interactButton.gameObject.SetActive(false);
62
        //particleSystem.SetActive(false);
63
64
65
    }

}