Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Bhargav5530 · Apr 07, 2015 at 09:45 AM · uibuttonbutton trigger events

Problem with button On Click

I am using unity 4.6.3. I am new to unity so I watched several video tutorials on youtube all the step i did that was in tutorial. I tried everything but I can't find solution of my problem.

In my project I created a scene "MainMenu" In this scene there are two buttons named "Start Game" & "Exit Game". There is an empty game object also with position (0,0,0) and add a script "mainMenuButtons" to it.

Here is my script "mainMenuButtons"

 public class mainMenuButtons : MonoBehaviour {

 void StartGame(){
     Application.LoadLevel (1);
 }

 void ExitGame(){
     Application.Quit ();
 }

}

Now I want to assign on click event on "Start Game" buttons to this StartGame() function. So I followed the steps click on StartButton. Click on "+" sign below the On Click(). When I click "+" sign I show 3 items here is a screen shot

alt text

I draged an empty game object i.e. UIManager. click on No Function and select a script "mainMenuButtons" but there is no StartGame() function or ExitGame() function.

Here is a screenshot

alt text

All the tutorial show the StartGame function but in my case it is not

am i making any mistake? plz help me

sorry for my english & Thanks in Advance

screen-shot-2015-04-06-at-123241-pm.png (12.3 kB)
screen-shot-2015-04-06-at-123508-pm.png (45.7 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
0
Best Answer

Answer by Bhargav5530 · Apr 14, 2015 at 10:29 PM

I found answer my self. This may help others who are new to unity3d. Just add a public keyword. by default the function in unity is private and if you declare a private function then the outside the unity inspector can't use those function. so you need to assign a public function.

Here is my script and it works perfectly.

 public class mainMenuButtons : MonoBehaviour {
  
 public void StartGame(){
      Application.LoadLevel (1);
  }
  
  public void ExitGame(){
      Application.Quit ();
  }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Buttons not working properly. 0 Answers

UI button in Panel not clickable 2 Answers

why won't my add button script work?!? (help appreciated) 2 Answers

Issue with spawning buttons and assigning listeners 1 Answer

Two buttons behaving entirely differently (despite similar logic in code)? 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