using UnityEngine;
using UnityEngine.UI;
public class BalancerPad : InteractFunction
{
//This is attached to the physical panel. This is the ACTUAL balancer with the actual correct balancer value.
//Balancer Puzzle refers to he Balancer UI object
public GameObject balancerPuzzle;
//This is the SCRIPT on balancer UI that handles updating the slider and telling the balancer pad the puzzle is complete
public BalancerUI balancerUI;
//This handles player's camera and movement to focus on the item.
public GameObject player;
public PlayerMovement movementScript;
public PlayerCam cameraScript;
public PlayerRaycast raycastScript;
//These are the cameras to swap between on the balancer and player
public GameObject balancerCam;
public GameObject playerCam;
//I don't remember what this does. I think this is primarily just so I can tell it to clear script manager's current interact function, which would be this.
public InteractScript interactScript;
//UsingBalancer handles allowing the player to enter and exit the puzzle, and puzzleComplete will trigger the win result.
public bool usingBalancer;
public bool puzzleComplete;
//This is... uncertain. This stays here but realistically could change to activate another function or simply disable another game object. For testing purposes, it will simply be turned off.
public GameObject itemToActivate;
//The correct value that the Balancer UI has to take from.
public int correctValueBP;
//gotta clear the panel buttons...
public Image balancerPanel1;
public Image balancerPanel2;
public Image balancerPanel3;
public Image balancerPanel4;
//The crosshair I forgot to add several times
public Image crosshair;
public void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
movementScript = player.GetComponent<PlayerMovement>();
cameraScript = player.GetComponent<PlayerCam>();
raycastScript = player.GetComponent<PlayerRaycast>();
playerCam = GameObject.FindGameObjectWithTag("MainCamera");
}
private void Update()
{
if ((usingBalancer) && (Input.GetKeyDown(KeyCode.E)))
{
EscapeBalancer();
}
if (puzzleComplete)
{
if (itemToActivate != null)
{
EscapeBalancer();
//This could also realistically be changed to just swap to another image file
balancerPanel1.color = Color.white;
balancerPanel2.color = Color.white;
balancerPanel3.color = Color.white;
balancerPanel4.color = Color.white;
//This can be exchanged for an animation.
itemToActivate.SetActive(false);
this.enabled = false;
}
else
{
Debug.Log("The door is opened but nothing was ever actually set to open");
}
}
}
public override void InteractMethod()
{
usingBalancer = true;
//Lock player in place
movementScript.enabled = false;
cameraScript.enabled = false;
raycastScript.enabled = false;
crosshair.enabled = false;
//Swap to balancer cam
playerCam.SetActive(false);
balancerCam.SetActive(true);
//Free mouse
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
//Tells the balancer UI what to compare against
balancerUI.balancerPad = this;
balancerUI.correctValueBUI = correctValueBP;
//Makes the balancer UI visible
balancerPuzzle.SetActive(true);
}
public override void InteractMethodDenial()
{
Debug.Log(itemToActivate.name + " is already open");
}
private void EscapeBalancer()
{
Cursor.lockState = CursorLockMode.Locked;
//this should be an escape
movementScript.enabled = true;
cameraScript.enabled = true;
raycastScript.enabled = true;
crosshair.enabled = true;
//Lock the cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
//Swap back to player cam
playerCam.SetActive(true);
balancerCam.SetActive(false);
//Don't remember why I did this... maybe just clean up?
balancerUI.correctValueBUI = 0;
//Turn off puzzle UI
balancerPuzzle.SetActive(false);
//Clears the interact script items
interactScript.interactableObject = null;
interactScript.interactFunction = null;
//Noticed that balancer puzzle doesn't set this pad to null. I don't remember why I did it on the pin puzzle, but it works there
balancerUI.balancerPad = null;
usingBalancer = false;
}
}