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(); 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; } }