Added Game Logic

Added chest logic for key press
Added Door openning script
Openning doors on start (for now)
Added UI for chest openning
This commit is contained in:
2025-06-29 21:16:15 +02:00
parent 269099e24e
commit c1b15326aa
9 changed files with 503 additions and 239 deletions

View File

@@ -5,20 +5,51 @@ public class ChestLogic : MonoBehaviour
private Animator animator;
private bool isOpen = false;
private bool isPlayerInRange = false;
private GameObject canvas;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
animator = GetComponent<Animator>();
canvas = GameObject.Find("UI Canvas");
if (canvas == null) Debug.LogWarning("ChestUIText GameObject not found in the scene. Please ensure it exists.");
}
// Update is called once per frame
void Update()
{
if (!isPlayerInRange)
return;
if (Input.GetKeyDown(KeyCode.E)) // Detekce stisku klávesy E
{
Debug.Log("E key pressed");
if (!isOpen)
{
animator.SetTrigger("Open");
isOpen = true;
// Deactivate the ChestUIText when the chest is opened
if (canvas != null)
{
Transform chestTextTransform = canvas.transform.Find("ChestUIText");
if (chestTextTransform != null)
{
chestTextTransform.gameObject.SetActive(false);
}
}
}
/*else
{
animator.SetTrigger("Close");
isOpen = false;
}*/
}
}
private void OnMouseDown()
/*private void OnMouseDown()
{
Debug.Log("Chest clicked");
if (!isOpen)
@@ -31,5 +62,51 @@ public class ChestLogic : MonoBehaviour
animator.SetTrigger("Close");
isOpen = false;
}
}*/
private void OnTriggerEnter(Collider other)
{
// Check if the chest is not already open
if (!isOpen)
{
if (other.CompareTag("Player"))
{
isPlayerInRange = true;
Debug.Log("Player entered chest range");
// Activate the ChestUIText when the player enters the range
if (canvas != null)
{
Transform chestTextTransform = canvas.transform.Find("ChestUIText");
if (chestTextTransform != null)
{
chestTextTransform.gameObject.SetActive(true);
}
}
}
}
}
private void OnTriggerExit(Collider other)
{
// Check if the chest is already open
if (isOpen)
return;
if (other.CompareTag("Player"))
{
isPlayerInRange = false;
Debug.Log("Player left chest range");
// Deaktivate the ChestUIText when the player leaves the range
if (canvas != null)
{
Transform chestTextTransform = canvas.transform.Find("ChestUIText");
if (chestTextTransform != null)
{
chestTextTransform.gameObject.SetActive(false);
}
}
}
}
}