- Home /
The question is answered, right answer was accepted
More problems with my weapon wheel (minor ones this time)
so my weapon wheel is up and running real good with the new swapping implemented...i just have a few minor problems.....
when i first start the game and open the weapon wheel, the cursor doesn't appear until i press escape atleast once .....
i have set my weaponwheel so that when the player holds down a certain key (f as of now)....it remains active and disabled....but this causes a strange problem that the sprite swap (embedded in the buttons) doesn't function correctly when highlighting the button through hover.....this problem is solved if i use a GetKeyDown based enable and disable metod...but since i want to keep them both as options.....i need to know the solution....
Since in unity, buttons can be directly controlled by keyboard....the same happens with the buttons on my wheel...with the difference being that the wheel has 16 buttons, since each weapon marker is semicircular and is hence occupied by four buttons each.....i want to disable the key bindings of the buttons....
script 1
Here are my UImanager(basically manages the pausing and all)...and weapon wheel script...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class UImanager : MonoBehaviour
{
public GameObject pausemenu;
public GameObject hud;
public WeaponWheel wheel;
public string pauseavailablity = "available";
public bool pauseactive;
public bool initialpause = false;
public bool pausing;
// Start is called before the first frame update
void Start()
{
hud.SetActive(true);
pausemenu.SetActive(false);
pauseactive = initialpause;
}
public void Resume()
{
FindObjectOfType<AudioManager>().PlayClip("resume1");
pausing = false;
}
public void Pause()
{
FindObjectOfType<AudioManager>().PlayClip("pause1");
pausing = true;
}
// Update is called once per frame
void Update()
{
if(SceneManager.GetActiveScene().buildIndex != 0)
{
if(pauseavailablity == "available")
{
if(Input.GetButtonDown("Cancel") && pausing && !wheel.wheelactive)
{
Resume();
}
else if(Input.GetButtonDown("Cancel") && !pausing && !wheel.wheelactive)
{
Pause();
}
if(pausing)
{
pauseactive = true;
pausemenu.SetActive(true);
Cursor.lockState = CursorLockMode.Confined;
}
else
{
pauseactive = false;
pausemenu.SetActive(false);
}
if(wheel.wheelactive)
{
pauseactive = true;
Cursor.lockState = CursorLockMode.Confined;
}
else if(!pausing)
{
pauseactive = false;
}
}
else
{
Cursor.lockState = CursorLockMode.Confined;
}
}
}
}
script 2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class UImanager : MonoBehaviour
{
public GameObject pausemenu;
public GameObject hud;
public WeaponWheel wheel;
public string pauseavailablity = "available";
public bool pauseactive;
public bool initialpause = false;
public bool pausing;
// Start is called before the first frame update
void Start()
{
hud.SetActive(true);
pausemenu.SetActive(false);
pauseactive = initialpause;
}
public void Resume()
{
FindObjectOfType<AudioManager>().PlayClip("resume1");
pausing = false;
}
public void Pause()
{
FindObjectOfType<AudioManager>().PlayClip("pause1");
pausing = true;
}
// Update is called once per frame
void Update()
{
if(SceneManager.GetActiveScene().buildIndex != 0)
{
if(pauseavailablity == "available")
{
if(Input.GetButtonDown("Cancel") && pausing && !wheel.wheelactive)
{
Resume();
}
else if(Input.GetButtonDown("Cancel") && !pausing && !wheel.wheelactive)
{
Pause();
}
if(pausing)
{
pauseactive = true;
pausemenu.SetActive(true);
Cursor.lockState = CursorLockMode.Confined;
}
else
{
pauseactive = false;
pausemenu.SetActive(false);
}
if(wheel.wheelactive)
{
pauseactive = true;
Cursor.lockState = CursorLockMode.Confined;
}
else if(!pausing)
{
pauseactive = false;
}
}
else
{
Cursor.lockState = CursorLockMode.Confined;
}
}
}
}
Any and all help is appreciated, Thanks in Advance!
Problem 2 solved itself somehow(didn't even touch a thing)...so i guess you can say only 1 and 3 remain
Answer by DenisIsDenis · Jul 08, 2021 at 03:29 AM
You have attached two identical scripts, so it is impossible to see what happens when you open the WeaponWheel
.
Problem 1: The following code can be used to make the cursor visible:
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Confined; // or .None
For example, you can call this function when opening the WeaponWheel
:
void ShowCursor ()
{
if (! Cursor.visible || Cursor.lockState == CursorLockMode.Locked)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Confined;
}
}
Problem 2: As far as I can see, it has already been resolved.
Problem 3: To disable the control of the Unity Buttons from the keyboard, you must disable navigation by these buttons (this also works with other types of UI elements):
oops sorry looks like i made a fatal mistake with attaching the scripts there
Thanks the script you provided is working good......so can i know what's the difference between using this and simply putting
Cursor.lockState = CursorLockMode.Confined;
Most likely, after changing lockState
, Unity is waiting for some action from the user to make the cursor visible. And setting the visibility manually allows you to make the cursor visible at the same moment when lockState
is set.
hmmm...i guess that makes sense....the cursor never becomes visible unless esc is clicked....i assumed it was because of the pause menu but it appears to be an editor shortcut
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Move to Mouse acting odd... 0 Answers
Trouble detecting button release with Input.GetButtonUp() 1 Answer
Animation not working 1 Answer