78 lines
1.7 KiB
C#
78 lines
1.7 KiB
C#
|
using Polyart;
|
||
|
using Unity.VisualScripting;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class MiniGameManager : MonoBehaviour
|
||
|
{
|
||
|
[Header("Canvas GameObjects")]
|
||
|
public GameObject miniGameCanvas;
|
||
|
|
||
|
|
||
|
|
||
|
void Awake()
|
||
|
{
|
||
|
if (miniGameCanvas != null)
|
||
|
{
|
||
|
miniGameCanvas.SetActive(false);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
void OnTriggerEnter(Collider other)
|
||
|
{
|
||
|
FirstPersonController_Polyart player = other.GetComponent<FirstPersonController_Polyart>();
|
||
|
CharacterController characterController = player.GetComponent<CharacterController>();
|
||
|
if (player != null && characterController != null)
|
||
|
{
|
||
|
|
||
|
|
||
|
// Disable player movement
|
||
|
player.DisablePlayer();
|
||
|
// Show the mini-game canvas, and enable the cursor to allow player to answer
|
||
|
if (miniGameCanvas != null)
|
||
|
{
|
||
|
miniGameCanvas.SetActive(true);
|
||
|
}
|
||
|
|
||
|
Cursor.lockState = CursorLockMode.None;
|
||
|
Cursor.visible = true;
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
public void YesAnswer()
|
||
|
{
|
||
|
miniGameCanvas.SetActive(false);
|
||
|
Cursor.lockState = CursorLockMode.Locked;
|
||
|
LoadingScene.Instance.BeginMiniGame();
|
||
|
|
||
|
}
|
||
|
public void NoAnswer()
|
||
|
{
|
||
|
|
||
|
// Hide the cursor and lock it back to the game view
|
||
|
Cursor.lockState = CursorLockMode.Locked;
|
||
|
Cursor.visible = false;
|
||
|
|
||
|
// Hide the mini-game canvas
|
||
|
if (miniGameCanvas != null)
|
||
|
{
|
||
|
miniGameCanvas.SetActive(false);
|
||
|
|
||
|
}
|
||
|
// Re-enable player movement
|
||
|
FirstPersonController_Polyart player = FindAnyObjectByType<FirstPersonController_Polyart>();
|
||
|
if (player != null)
|
||
|
{
|
||
|
player.EnablePlayer();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|