- Home /
GUI button to Unity5 Button OnClic function
Hello I’m a scripting beginner so I would appreciate a clear answer if possible.
I bought a script but I need to adapt it to my needs. Basically my needs are to use unity 5 canvas buttons instead the example supplied buttons that happen to be in the same .cs file as the action I need to use. The script plays YouTube videos on mobile. I've tested it and it works out of the box, but is not working with the customization I've made. I'm supposed to create an empty object and put 2 scripts there.
This is the script SUPPLIED example that works perfectly:
public class GetVideo : MonoBehaviour {
public string videoId1 = "";
void OnGUI()
{
GUI.depth = 0;
if(GUI.Button(new Rect(0,0,Screen.width,Screen.height/2),"Load Video 1"))
{
Handheld.PlayFullScreenMovie(YoutubeVideo.Instance.RequestVideo(videoId1, 720));
Debug.Log("The video only plays on mobile device, if you receive one big url on console all it's ok");
}
} }
This is the script I’ve done to use along with Unity5 Button’s onClic function:
public class GetVideo : MonoBehaviour {
public string videoId1 = "";
public void OnClic()
{
{
Handheld.PlayFullScreenMovie(YoutubeVideo.Instance.RequestVideo(videoId1, 720));
Debug.Log("The video only plays on mobile device, if you receive one big url on console all it's ok");
}
}
}
Then I seek for what I think is the correct function:
!
I appreciate if someone gives me a hint on what I'm missing here? Thanks!!
Answer by troien · Mar 03, 2016 at 06:49 PM
Well, you actually selected the wrong function, BroadCastMessage is not the one you want, you are looking for OnClic (the name of your function/method). However, in the screenshot the correct method isn't shown for some reason.
You called your method "OnClic" which is located inside the "GetVideo" class. So you are correctly selecting GetVideo, but that dropdown list you get should contain OnClic ;)
Do you have any compiler errors? (outside of playmode, open the console and click clear) If any errors persist in the list, you will need to fix those first, as the list with methods/functions doesn't get updated while there are compiler errors
Another thing to note is that your method (OnClic) needs to be public, but in the code you provided that's already the case...