using System.Collections; using System.Collections.Generic; using UnityEngine.InputSystem; using TMPro; using UnityEngine; public class PlayerLogic : MonoBehaviour { [SerializeField] private bool isALootableObjectNearby = false; [SerializeField] private bool lootNextTick = false; [SerializeField] private int coinCount = 0; [SerializeField] private int keyCount = 0; [SerializeField] private Vector3 respawnLocation; [SerializeField] private Vector3 initalSpawnLocation; [SerializeField] public GameObject GameOverMenu; [SerializeField] public GameObject WinMenu; public void addCoins(int number){ coinCount += number; TMP_Text textCoins = GameObject.Find("CoinsText").GetComponent(); textCoins.text = "Coins: "+coinCount+"/150"; if (coinCount == 150){ GameObject.Find("InvisibleWall").SetActive(false); } } public void addKeys(int number){ keyCount += number; TMP_Text textKeys = GameObject.Find("KeysText").GetComponent(); textKeys.text = "Keys: "+keyCount; } public void die(){ this.gameObject.SetActive(false); GameOverMenu.SetActive(true); } public void win(){ this.gameObject.SetActive(false); WinMenu.SetActive(true); } void OnTriggerEnter(Collider other) { if (other.tag == "killOnContact") {} else if (other.tag == "Coin") { addCoins(1); } else if (other.tag == "Key"){ addKeys(1); } else if (other.tag == "Lootable") isALootableObjectNearby = true; else if (other.tag == "WinCondition"){ win(); } } void OnTriggerStay(Collider other) { if (other.tag == "Lootable"){ if (isALootableObjectNearby && lootNextTick){ if (keyCount > 0){ Lootable lootableObject = other.GetComponent(); addCoins(lootableObject.loot()); addKeys(-1); } lootNextTick = false; } } } public void Inspect(){ lootNextTick = true; } void OnTriggerExit(Collider other) { if (other.tag == "Lootable") isALootableObjectNearby = false; } }