- Home /
Having issues with the UI Button?
So I'm having a lot of trouble with the UI Button right now, all I'm trying to do is add a button to change the scene to something else.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class UIManagerScript : MonoBehaviour
{
public void GoTo()
{
Debug.Log ("Clicked");
SceneManager.LoadScene (1);
}
}
I see other people using.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class UIManagerScript : MonoBehaviour
{
public void GoTo()
{
Debug.Log ("Clicked");
Application.loadLevel (1);
}
}
But neither of these ways works. Also when I try to go into playmode just to see the buttons highlight, nothing happens. It's like the buttons don't have a raycast or anything like that. Idk I haven't used UI elements at all so I have no idea how to use them. If someone could help me that would be greatly appreciated! Thank you
hi
first your button must be on top layer of canvas so it will not covered by other ui components
and select goto() method for button from inspector (i think you forgot it)
is "clicked" debug when you press button ?
Yeah I just have the "clicked" there so I could see if it was being clicked at all, and I tried moving the button to a different layer but no luck there either.
Put your script on the Button- just drag it on there. Then select the button and look in the inspector and click + on the OnClick event.
A slot appears, now even though you have the button selected drag the button onto that slot. Then from the drop down select
UI$$anonymous$$anagerScript -> GoTo
Now when clicked the button will call that scripts GoTo function. REally look at the EventSystem tutorials as it's fantastic.
I tried this and to no luck. I'll have to go to that tutorial to try and get a better understanding of it all.
Answer by shanzebali · Jun 05, 2016 at 10:38 AM
Assign this function to the button, and add the scene to your build settings. If it debugs log "clicked".
Answer by technano · Jun 06, 2016 at 05:10 AM
I feel very foolish but I found the solution. I had deleted the eventsystem, now that it's back everything works fine!!
Your answer