For turning left and right, i used coroutines, but i set the fps to 60 capped, and it was really slow, so i switched to just functions, and now turning is instantaneous instead of having a smoother longer turn.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.Rendering.DebugUI;
public class PlayerManager : MonoBehaviour
{
public Transform player;
public GameObject monitorScreen;
public GameObject leftTurnImage;
public GameObject rightTurnImage;
public GameObject leftResetTurnImage;
public GameObject rightResetTurnImage;
public GameObject upTurnImage;
public GameObject upResetTurnImage;
public GameManager gameMan;
public Camera pCam;
public float scrnOn;
public bool turnedRight;
public bool turnedLeft;
public bool turnedUp;
void Start()
{
monitorScreen.SetActive(false);
scrnOn = -1;
pCam.fieldOfView = 55;
turnedRight = false;
turnedLeft = false;
turnedUp = false;
leftResetTurnImage.SetActive(false);
rightResetTurnImage.SetActive(false);
upResetTurnImage.SetActive(false);
leftTurnImage.SetActive(true);
rightTurnImage.SetActive(true);
upTurnImage.SetActive(true);
}
void Update()
{
if (scrnOn == -1 && turnedLeft == false && turnedRight == false && turnedUp == false)
{
monitorScreen.SetActive(false);
if (Input.GetKeyUp(KeyCode.Space))
{
camFOVDUpDelay();
}
}
if (scrnOn == 1 && turnedLeft == false && turnedRight == false && turnedUp == false && gameMan.jumpscare == false)
{
monitorScreen.SetActive(true);
if (Input.GetKeyUp(KeyCode.Space))
{
camFOVDownDelay();
}
}
if (Input.GetKeyUp(KeyCode.Space) && turnedLeft == false && turnedRight == false && turnedUp == false && gameMan.jumpscare == false)
{
Debug.Log("Monitor On");
scrnOn = scrnOn * -1;
}
if(gameMan.jumpscare)
{
pCam.fieldOfView = 55;
player.transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
public void camFOVDUpDelay()
{
for (int i = 55; i > 30; i--)
{
pCam.fieldOfView = i;
}
}
public void camFOVDownDelay()
{
for (int i = 30; i < 55; i++)
{
pCam.fieldOfView = i;
}
}
public IEnumerator turnLeftDelay()
{
yield return new WaitForSeconds(0.5f);
leftTurnImage.SetActive(true);
rightTurnImage.SetActive(true);
}
public IEnumerator turnRightDelay()
{
yield return new WaitForSeconds(0.5f);
rightTurnImage.SetActive(true);
leftTurnImage.SetActive(true);
}
public void rotateRightDelay()
{
for (int i = 0; i < 33; i++)
{
player.Rotate(0, 1, 0);
}
}
public void rotateLeftDelay()
{
for (int i = 0; i > -33; i--)
{
new WaitForSeconds(0.1f);
player.Rotate(0, -1, 0);
}
}
public void rotateRightResetDelay()
{
for (int i = -33; i < 0; i++)
{
player.Rotate(0, 1, 0);
}
}
public void rotateLeftResetDelay()
{
for (int i = 33; i > 0; i--)
{
player.Rotate(0, -1, 0);
}
}
public void upTurnDelay()
{
for (int i = 2; i > -85; i--)
{
player.Rotate(-1, 0, 0);
}
}
public void upResetTurnDelay()
{
for (int i = -85; i < 2; i++)
{
player.Rotate(1, 0, 0);
if (i == 1)
{
turnedUp = false;
}
}
}
public IEnumerator leftRightUpImagesDelay()
{
yield return new WaitForSeconds(0.5f);
rightTurnImage.SetActive(true);
leftTurnImage.SetActive(true);
upTurnImage.SetActive(true);
}
public void rotateRight()
{
if (scrnOn == -1 && turnedUp == false && gameMan.jumpscare == false)
{
turnedRight = true; // boolean turnedRight sets to true
rotateRightDelay(); // rotates player head right
leftTurnImage.SetActive(false); // disables left turn image
rightTurnImage.SetActive(false); // disables right turn image
leftResetTurnImage.SetActive(true); // enables left reset turn image
}
}
public void rotateLeft()
{
if (scrnOn == -1 && turnedUp == false && gameMan.jumpscare == false)
{
turnedLeft = true; // boolean turnedleft sets to true
rotateLeftDelay(); // rotates player head left
rightTurnImage.SetActive(false); // disables right turn image
leftTurnImage.SetActive(false); // disables left turn image
rightResetTurnImage.SetActive(true); // enables right reset turn image
}
}
public void resetRotateRight()
{
rotateRightResetDelay(); // player head rotates to middle from left
rightResetTurnImage.SetActive(false); // disables right reset turn image
StartCoroutine(turnRightDelay()); // enables right turn image
turnedRight = false;
}
public void resetRotateLeft()
{
rotateLeftResetDelay(); // player head rotates to middle from right
leftResetTurnImage.SetActive(false); // disables left reset turn image
StartCoroutine(turnLeftDelay()); // enables left turn image
turnedLeft = false;
}
public void upTurn()
{
if (scrnOn == -1 && turnedLeft == false && turnedRight == false && gameMan.jumpscare == false)
{
turnedUp = true;
upTurnDelay();
leftTurnImage.SetActive(false);
rightTurnImage.SetActive(false);
upTurnImage.SetActive(false);
upResetTurnImage.SetActive(true);
}
}
public void upResetTurn()
{
upResetTurnDelay();
StartCoroutine(leftRightUpImagesDelay());
upResetTurnImage.SetActive(false);
}
}