Hey community
So I’ve gotten pretty well into Unity and how it works.
However I have en issue, that google did not help me find any answers to, hope you can.
I have this wardrobe in my game where I can change outfit on my main character.
When you activate the wardrobe an image with be enabled that has two buttons.
I wanted to show my highlighted button with a given letter (>) in front of the name, rather than changing the color tint. Seems like there aren’t any transitions available in Unity currently to do this.
So I made this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ButtonsWardrobe : MonoBehaviour, ISelectHandler, IDeselectHandler
{
public GameObject button;
public Text dialogText;
public string dialog;
private string dialogOld;
public bool defaultSelection;
// Start is called before the first frame update
void Start()
{
dialogOld = dialogText.text;
if (defaultSelection)
{
EventSystem.current.SetSelectedGameObject(button);
}
}
// Update is called once per frame
void Update()
{
}
public void OnSelect(BaseEventData eventData)
{
dialogText.text = dialog + dialogText.text;
}
public void OnDeselect(BaseEventData eventData)
{
dialogText.text = dialogOld;
}
}
It works perfectly the first time I use the button.
There are two buttons: Yes and No
If you click “Yes” it will change the animation to the one with the new gear and that also changes the image for it to load on next activation (Since we want the old gear to now be in the wardrobe). This also works perfectly fine, so the second time I activate the Wardrobe it will have activated another image with two buttons Yes and No like before, which will make you put on your old clothes.
Now here comes the issue:
When I open the Wardrobe the third time I am unable to control the selector I can’t select neither yes nor no. UNLESS I click on either with the mouse.
In my tests it seems that
EventSystem.current.SetSelectedGameObject(button);
stops working when you swap between images (Since if i moved it down to void Update() it works fine and i am able to keep changing gear.
However that is not a suitable solution, since it will keep changing the selected button to the given button making you unable to choose “No”.
I hope this makes any sense at all.
-YoShI