King UI fixes

>Q now toggles the UI
>The UI can no longer go offscreen
>The Panel that holds the King's buttons was resized, and its scaling
was changed
This commit is contained in:
Katherine
2022-04-12 14:12:27 -05:00
parent 84368a0eb2
commit b16b8a505f
3 changed files with 56 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ public class RadialMenu : MonoBehaviour
{
bool UIOn = false;
bool ButtonUp = true;
public GameObject King;
public Camera cam;
@@ -14,28 +15,52 @@ public class RadialMenu : MonoBehaviour
[SerializeField]
private Text UItext;
private float xBound = 1920f;//Resolution
private float yBound = 1080f;
private float xSize;
private float ySize;
void Start()
{
xSize = GetComponent<RectTransform>().sizeDelta.x / 2;//Converts the size of the Panel into the bounds of the screen
ySize = GetComponent<RectTransform>().sizeDelta.y / 2;
xBound -= xSize;
yBound -= ySize;
}
// Update is called once per frame
void Update()
{
if (UIOn == false) {
screenPoint = Input.mousePosition;
screenPoint.z = 120f;
screenPoint.x = Mathf.Clamp(screenPoint.x, xSize, xBound);//Uses the calculated bounds to keep the UI on the screen
screenPoint.y = Mathf.Clamp(screenPoint.y, ySize, yBound);
transform.position = cam.ScreenToWorldPoint(screenPoint);//Moved the UI to where the mouse is
}
if(Input.GetAxis("RadialMenu") > 0) {//Pressing Q makes the UI appear
if(Input.GetAxis("RadialMenu") > 0 && UIOn == false && ButtonUp == true) {//Pressing Q makes the UI appear, if it is off
ButtonUp = false;
if (King.GetComponent<KingPlace>().FirstPlacing == true) {
King.GetComponent<KingPlace>().CancelPlacing();
}
MenuOn();
}
if (Input.GetAxis("RadialMenu") < 0) {//Pressing E makes the UI dissapear
else if (Input.GetAxis("RadialMenu") > 0 && UIOn == true && ButtonUp == true) {//Pressing Q makes the UI dissapear, if it is on
ButtonUp = false;
MenuOff();
}
if(Input.GetAxis("RadialMenu") == 0)
{
ButtonUp = true;
}
}
private void MenuOn()
{
UItext.text = "Press E to Close Menu";
UItext.text = "Press Q to Close Menu";
foreach (Transform child in transform) { //Turns on all of the different buttons attached to this panel and stops it from moving
child.gameObject.SetActive(true);
UIOn = true;