Good day,
I’ve been pogramming on a mobile app for a few weeks. Now I have a function that should change an Int value at the touch of a button (the button is in a panel). So far evrythink was functionable, the problem is when I put other buttons into the panel, the button for the change int value function no longer works (for code see below) I first thought that this is because the button was below / Above the other but I tested all this and it did not worked.
I think its a Bug, because wen i put a other Button at the accactlie same Position in Play Mode it will Work.
Thanks in Advance
//LevelManager
public void ChangeLevelSizeTo2()
{
LevelSlectionsMenu = 2;
}
//Change Function
public void ChangeTo2()
{
GameObject.Find("GameManager");
levelManager.ChangeLevelSizeTo2();
}
You misunderstand how GameObject.Find() works. It returns the thing it finds. This line above does absolutely nothing of any value. It may or may not find something, whatever it does, you do nothing with the value.
Generally speaking, do NOT use GameObject.Find(); It is an extremely problematic API that almost always results in people coming to the forum confused about why something does not work. And here you are.
As for your actual UI problem, we know that buttons still work, so in order to help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
is this code even running? which parts are running? how often does it run?
what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.
You could also just display various important quantities in UI Text elements to watch them change as you playtest.
If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.
Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:
Thank you for the feedback that Debug.Log Metode has worked, but I don’t know how to solve the problem. I applied the script to another button and there both worked, i created a second Panelwith the stuff. This Panel also works, but if I still make a new page or the old one it doesn’t work on this one. If the problem really is because the Find Mehode, I don’t know how to fix the problem because this object is cross-border and I can’t set it any other wayis there any other way to do this?