Can't Click Button with Cursor in FPS
I am pretty new to unity--
I am trying to have a quest pop up, and click the accept or decline button. Everything functions the way it should, except I cannot get my cursor to show up during the quest prompt and disappear after hitting accept or decline.
I've tried coding so many different ways with locking the cursor and making the cursor visible/invisible, but nothing seems to stick.
At the moment I have the FPSController ticked option "lock and hide cursor", with the code
void Update() {
TheDistance = PlayerCasting.DistancefromTarget;
}
void OnMouseOver(){
if (TheDistance <= 3) {
ActionDisplay.SetActive(true);
ActionText.SetActive(true);
Cursor.lockState = CursorLockMode.None;
}
if (Input.GetButtonDown("Action") && TheDistance <= 3)
{
ActionDisplay.SetActive(false);
ActionText.SetActive(false);
UIQuest.SetActive(true);
NoticeCam.SetActive(true);
ThePlayer.SetActive(false);
}
}
void OnMouseExit() {
ActionDisplay.SetActive (false);
ActionText.SetActive (false);
Cursor.lockState = CursorLockMode.Locked;
}
}
Answer by rage_co · Aug 06, 2021 at 01:52 PM
I had encountered a similar problem, but thanks to @DenisIsDenis ...i got it sorted...it appears that you have to first set the cursor visible to make it appear...i will share the simple code Denis gave me
void ShowCursor ()
{
if (! Cursor.visible || Cursor.lockState == CursorLockMode.Locked)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
just call ShowCursor whenever you want to make the cursor visible.....and it should work for you
Your answer
![](https://koobas.hobune.stream/wayback/20220613041255im_/https://answers.unity.com/themes/thub/images/avi.jpg)