Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ivabibliocad · Mar 03, 2016 at 01:22 PM · guibuttonunity5onclickyoutube

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. alt text

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: alt text

!

I appreciate if someone gives me a hint on what I'm missing here? Thanks!!

convert-gui-button-to-a-unity-5-ui-button-1.png (80.3 kB)
3.png (27.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

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...

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Mar 04, 2016 at 04:29 AM 0
Share

I converted the comment into an answer ^^.

avatar image HardikMaru2001 · Mar 04, 2016 at 08:02 AM 0
Share

Perfect answer by @troien. Just one more thing I would you to keep in $$anonymous$$d @Bunny83 that if your must be public as well as without any parameters. Because you can not any method through UI Button which has any parameter even if method's access modifier is public.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Putting a delay in a button OnClick ? (Javascript) 3 Answers

How to change button image on click 2 Answers

OnTrigger Down, Call the Button's OnClicked event 2 Answers

How to trigger a button click from script 3 Answers

onClick.AddListener doesn't get assigned to button. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges