Hi there, is there a way that I could create a false cursor so players can interact with menus while the real cursor is still locked. If I unlock then try to relock the cursor afterwards it is still unlocked until the player clicks on the window again and can move outside the game window.
Sorry forgot to add, I have the fake cursor already, I just dont know how to make it interact with the UI’s
I ended up using this to move the cursor when a menu was active.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
float xRotation;
float yRotation;
public GameObject pauseMenuCursor;
public float pauseMenuCursorX = 0f;
public float pauseMenuCursorY = 0f;
public bool onMenu = false;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
if (onMenu == true)
{
if (pauseMenuCursorX >= 0 && pauseMenuCursorX <= Screen.width)
{
pauseMenuCursorX = pauseMenuCursorX + (Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX * 10);
}
else if (pauseMenuCursorX > Screen.width)
{
pauseMenuCursorX = Screen.width;
}
else
{
pauseMenuCursorX = 0f;
}
if (pauseMenuCursorY >= 0 && pauseMenuCursorY <= Screen.height)
{
pauseMenuCursorY = pauseMenuCursorY + (Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY * 10);
}
else if (pauseMenuCursorY > Screen.height)
{
pauseMenuCursorY = Screen.height;
}
else
{
pauseMenuCursorY = 0f;
}
pauseMenuCursor.transform.position = new Vector3(pauseMenuCursorX, pauseMenuCursorY, 0);
}
else if (onMenu == false)
{
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
}
And this to check if the cursor overlapped a button or ended it’s overlap
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResumeHoverControl : MonoBehaviour
{
public GameObject playerReference;
void OnTriggerEnter2D(Collider2D col)
{
Debug.Log("Hi");
if (col.gameObject.name.Contains("Interact Box"))
{
playerReference.GetComponent<Player>().overlappingResume = true;
}
}
void OnTriggerExit2D(Collider2D col)
{
if (col.gameObject.name.Contains("Interact Box"))
{
playerReference.GetComponent<Player>().overlappingResume = false;
}
}
}
Then this activates the click
if (playerCamera.GetComponent<PlayerCam>().onMenu == true)
{
if (overlappingResume == true)
{
pauseUI.GetComponent<PauseMenuUIScript>().Resume();
}
else if (overlappingControls == true)
{
}
else if (overlappingMainMenu == true)
{
}
else if (overlappingExitGame == true)
{
}
}
Is there a way though where I can have all the trigger events for a specific menu in the same script, or do I have to create a script on each menu object with OnTriggerEnter2D for it’s trigger volume, just feels like this should be possible.