TentInteractoins.cs 1.72 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
26
27
    }

    // Update is called once per frame
    void Update() {
        checkNearbyPlayers();
        if (interactable) {
mmaluschnig's avatar
mmaluschnig committed
28
            if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.E)) {
29
30
31
32
33
                DaytimeManager.beginPerformance();
            }
        }
    }

34
    private void checkNearbyPlayers() {
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        CapsuleCollider2D playerCol = player.GetComponent<CapsuleCollider2D>();
        Collider2D[] foundPlayers = new Collider2D[1];
        if (thisCollider.OverlapCollider(filter, foundPlayers) > 0) {
            if (!interactable) {
                EnterInteractable();
            }
            interactable = true;
        } else {
            if (interactable) {
                ExitInteractable();
            }
            interactable = false;
        }
    }

    void EnterInteractable() {
51
        interactButton.gameObject.SetActive(true);
52
        //particleSystem.SetActive(true);
53
54
55
    }

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

}