diff --git a/Assets/Prefab/Shop/Shop.prefab b/Assets/Prefab/Shop/Shop.prefab index f6c545c0eda7be365e9100495da6e305ab63724d..667adbd1fddcad8621ae7cf8ffe48c542c5d60a6 100644 --- a/Assets/Prefab/Shop/Shop.prefab +++ b/Assets/Prefab/Shop/Shop.prefab @@ -1146,7 +1146,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &1076336731131441806 Transform: m_ObjectHideFlags: 0 @@ -2273,6 +2273,7 @@ MonoBehaviour: uiShop: {fileID: 2894649308036582996} shopAlertUI: {fileID: 5972690824423832835} shopAlertFollow: {fileID: 7017381858224549934} + timerAlert: {fileID: 1838556968299405519} --- !u!1001 &7990290028326398621 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Shop/ShopAlertFollow.cs b/Assets/Scripts/Shop/ShopAlertFollow.cs index a453e0f5820cbb1eee9834b4d3be05d9fd30482f..c04490b970add78bc0fb7cd1c3a46506155ab3d2 100644 --- a/Assets/Scripts/Shop/ShopAlertFollow.cs +++ b/Assets/Scripts/Shop/ShopAlertFollow.cs @@ -8,6 +8,7 @@ public class ShopAlertFollow : MonoBehaviour void Update() { + if (player == null) return; Vector3 directionToPlayer = transform.position - player.transform.position; directionToPlayer.y = 0; diff --git a/Assets/Scripts/Shop/Shopkeeper.cs b/Assets/Scripts/Shop/Shopkeeper.cs index 1570c9b4883dce7c308a1be3449eafc55cce7aa0..3123be596e10b3ff6992316e697c0a5b3667d35f 100644 --- a/Assets/Scripts/Shop/Shopkeeper.cs +++ b/Assets/Scripts/Shop/Shopkeeper.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using TMPro; using UnityEngine; public class Shopkeeper : MonoBehaviour @@ -7,54 +8,43 @@ public class Shopkeeper : MonoBehaviour public GameObject uiShop; public GameObject shopAlertUI; public GameObject shopAlertFollow; + public TextMeshPro timerAlert; + + private bool isShopOpen = true; private bool isActiveShop = false; private GameObject player; + private Quest currentQuest; + private void Start() + { + currentQuest = QuestManager.currentQuest; + } private void Update() { + if(currentQuest == null || currentQuest != QuestManager.currentQuest) + { + currentQuest = QuestManager.currentQuest; + StartCoroutine(openShop(30)); + } + if (!isShopOpen) return; + if(player != null && Input.GetKeyDown(KeyCode.E)) { if (!isActiveShop) { - uiShop.GetComponent<UI_Shop>().Show(); - uiShop.GetComponent<UI_Shop>().player = player; - isActiveShop = true; - + activateShop(); } else { - uiShop.GetComponent<UI_Shop>().Hide(); - uiShop.GetComponent<UI_Shop>().player = null; - isActiveShop = false; - + deactivateShop(); } } - if (isActiveShop && player != null) - { - player.GetComponent<PlayerCamera>().enabled = false; - player.GetComponent<PlayerMovement>().enabled = false; - player.GetComponent<PlayerAttack>().enabled = false; - player.GetComponent<PlayerWeaponState>().enabled = false; - player.GetComponent<StatisticsManager>().enabled = false; - Cursor.lockState = CursorLockMode.None; - deactivateAlert(); - } - else if (isActiveShop == false && player != null) - { - player.GetComponent<PlayerCamera>().enabled = true; - player.GetComponent<PlayerMovement>().enabled = true; - player.GetComponent<PlayerAttack>().enabled = true; - player.GetComponent<PlayerWeaponState>().enabled = true; - player.GetComponent<StatisticsManager>().enabled = true; - Cursor.lockState = CursorLockMode.Locked; - activateAlert(); - } } private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { - activateAlert(); player = other.gameObject; + activateAlert(); } } @@ -62,21 +52,73 @@ public class Shopkeeper : MonoBehaviour { if (other.gameObject.tag == "Player") { - deactivateAlert(); player = null; + deactivateAlert(); } } private void activateAlert() { + if(!isShopOpen) return; shopAlertUI.SetActive(true); - shopAlertFollow.SetActive(true); shopAlertFollow.GetComponent<ShopAlertFollow>().player = player; + shopAlertFollow.SetActive(true); } private void deactivateAlert() { shopAlertUI.SetActive(false); - shopAlertFollow.GetComponent<ShopAlertFollow>().player = null; shopAlertFollow.SetActive(false); + shopAlertFollow.GetComponent<ShopAlertFollow>().player = null; + } + + private void activateShop() + { + uiShop.GetComponent<UI_Shop>().Show(); + uiShop.GetComponent<UI_Shop>().player = player; + isActiveShop = true; + if(player != null) { + player.GetComponent<PlayerCamera>().enabled = false; + player.GetComponent<PlayerMovement>().enabled = false; + player.GetComponent<PlayerAttack>().enabled = false; + player.GetComponent<PlayerWeaponState>().enabled = false; + player.GetComponent<StatisticsManager>().enabled = false; + Cursor.lockState = CursorLockMode.None; + deactivateAlert(); + } + } + + private void deactivateShop() + { + uiShop.GetComponent<UI_Shop>().Hide(); + uiShop.GetComponent<UI_Shop>().player = null; + isActiveShop = false; + if(player != null) { + player.GetComponent<PlayerCamera>().enabled = true; + player.GetComponent<PlayerMovement>().enabled = true; + player.GetComponent<PlayerAttack>().enabled = true; + player.GetComponent<PlayerWeaponState>().enabled = true; + player.GetComponent<StatisticsManager>().enabled = true; + Cursor.lockState = CursorLockMode.Locked; + activateAlert(); + } + } + + private IEnumerator openShop(int time) + { + timerAlert.text = time.ToString(); + isShopOpen = true; + Debug.Log("opening shop"); + while(time > 0) + { + yield return new WaitForSeconds(1f); + time--; + timerAlert.text = (time).ToString(); + } + isShopOpen = false; + if(isActiveShop) + { + deactivateShop(); + deactivateAlert(); + } } }