Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 LAFI · Feb 04, 2015 at 11:27 AM · uibuttonfacebook

new UI tools problem

i want to run this code with new ui tool, this is my code

 using UnityEngine;
 using System.Collections;
 
 public class FecebookLog : MonoBehaviour {
 
     void Awake()
     {
         FB.Init(SetInit, OnHideUnity);
     }
     /*public void ChangeToScene(string SceneLoad)
     {
         Application.LoadLevel(SceneLoad);
     }*/
     private void SetInit()
     {
         Debug.Log ("Init Done");
         if(FB.IsLoggedIn)
         {
             Debug.Log("FB Login ");
         } else {
             FBlogin();
         }
     }
     private void OnHideUnity(bool isGameShown)
     {
         if(!isGameShown)
         {
             Time.timeScale = 0;
         }
         else
         {
             Time.timeScale = 1;
         }
     }
 
   void FBlogin()
     {
         FB.Login("user_about_me  , user_birthday", AuthCallback);
 
     }
     void AuthCallback(FBResult result)
     {
         if(FB.IsLoggedIn)
         {
             Debug.Log("FB Login Work!!");
             Application.LoadLevel("Menu");
         }
         else
         {
 
             Debug.Log("FB Login Failed");
             Application.LoadLevel("FB");
 
         }
     }
     // Use this for initialization
 
 
 }

I created a new UI button (FB LOGIN) and I linked this code with this button, but the problem that this code on automatically when I enter in play mode, I want that this code works only I click on my button

Help me please Thank you

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mmmpies · Feb 04, 2015 at 11:30 AM

If you don't want it running until being clicked remove the Awake Function.

Both Awake and Start functions run when play is first clicked and Update runs every frame but your other functions will only get called by external events.

EDIT

OK Remove was the wrong word, rename that to something like

 public void IveBeenClicked()

Instead of Awake then copy that script onto the new UI button, click + in the OnClick part of the button in the inspector, a slot appears so drag your button (with this script on it) onto that slot. Next to that slot there's a dropdown so select your script name -> IveBeenClicked.

Then when you click that button it'll call that function, I'm assuming that's what you want anyway.

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 LAFI · Feb 04, 2015 at 03:23 PM 0
Share

Thank you for your answer :) @$$anonymous$$mmpies and if I delete Awake, where I move this code snippet

FB.Init(SetInit, OnHideUnity);

avatar image LAFI · Feb 05, 2015 at 04:30 PM 0
Share

ok i will do it now Thank you

avatar image
0

Answer by SuperMasterBlasterLaser · Feb 04, 2015 at 03:49 PM

You starting your FBlogin when your GameObject is AWAKE. You need to make your SetInit public and do not call it from Awake. In your editor on your Button UI, there is on click events. Attach your GameObject that contains FecebookLog script there and call your SetInit function.

Comment
Add comment · 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
0

Answer by AndresBarrera · Feb 04, 2015 at 03:51 PM

Are you using the OnClick event of the button?? Look at this video, around 10:30

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

New UI Button Dynamic onClick Listener problem 1 Answer

Script variable doesn't appear in UI's inspector 2 Answers

How to create a 4.6 UI button NOT from prefab NOT in unity editor only from C# 1 Answer

Is there a better way to access the single active Toggle in a ToggleGroup? 4 Answers

UI button dosent show function 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