StellarXipher/Assets/Scripts/OpenLogHandler.cs
EthanPisani c5d2c3cf8c
Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (push) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (pull_request) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (pull_request) Has been cancelled
add logs to level3
2025-04-20 14:05:11 -04:00

93 lines
2.8 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class OpenLogHandler : MonoBehaviour
{
public GameObject scrollableTextPanel; // Assign your "ScrollableTextPanel" in the Inspector
[SerializeField] private TextMeshProUGUI scrollableText; // Assign your TextMeshProUGUI component in the Inspector
[SerializeField] private string logText = "This is the log text that will be displayed in the scrollable panel."; // The text to display
[SerializeField] private GameObject contentPanel; // Assign your content panel in the Inspector
[Header("Player Control Locking")]
public GameObject[] crosshairs;
public MonoBehaviour playerMovementScript;
private bool isPanelOpen = false;
private void Update()
{
if (Input.GetMouseButtonDown(0)) // Left mouse button click
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.transform == transform) // Check if the clicked object is the one this script is attached to
{
Debug.Log("Clicked on the Log!");
ShowPanel();
}
}
}
if (isPanelOpen && Input.GetKeyDown(KeyCode.Escape))
{
ClosePanel();
}
}
void ShowPanel()
{
if (!scrollableTextPanel.activeSelf)
{
scrollableText.text = logText; // Set the text in the TextMeshProUGUI component
// set content to posY 0
RectTransform contentRect = contentPanel.GetComponent<RectTransform>();
contentRect.position = new Vector3(contentRect.position.x, 0, contentRect.position.z);
scrollableTextPanel.SetActive(true);
LockPlayerControl();
isPanelOpen = true;
}
}
void ClosePanel()
{
scrollableTextPanel.SetActive(false);
UnlockPlayerControl();
isPanelOpen = false;
}
void LockPlayerControl()
{
foreach (GameObject crosshair in crosshairs)
{
if (crosshair != null)
crosshair.SetActive(false);
}
if (playerMovementScript != null)
playerMovementScript.enabled = false;
Time.timeScale = 0f;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
public void UnlockPlayerControl()
{
foreach (GameObject crosshair in crosshairs)
{
if (crosshair != null)
crosshair.SetActive(true);
}
if (playerMovementScript != null)
playerMovementScript.enabled = true;
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}