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 Puffinlump · Mar 30, 2016 at 08:54 AM · scripting problemeventsfunctions

Event System Calling Functions but they dont Work (No errors)

I have a script linked to a button... Actually two... But here's my problem: The game runs with no errors (good) The events are being called (good, found out by the function name being shown) The functions are not doing anything? (bad)

Code in both scripts:
MenuButton:

 using UnityEngine;
 using System.Collections;
 
 public class MenuButton : MonoBehaviour {
     
     // Use this for initialization
     void Start ()
     {
     
     }
     
     // Update is called once per frame
     void Update ()
     {
     
     }
 
     void Click(int id)
     {
         Debug.Log(id);
         UnityEngine.SceneManagement.SceneManager.LoadScene(id);
     }
 }

ButtonHover:

 using UnityEngine;
 using System.Collections;
 
 public class ButtonHover : MonoBehaviour {
 
     public AudioSource HoverSound;
 
     // Use this for initialization
     void Start ()
     {
     
     }
     
     // Update is called once per frame
     void Update ()
     {
     
     }
 
     void Hover()
     {
         HoverSound.Play();
     }
 }

Both are c#.
https://i.gyazo.com/20b15e8d334746b52d560b7357d825b9.png
(By the way I know how to put an image in, unity won't let me do it by url for some reason.)
UPDATE: It appears that no scripts are working or outputting errors. What is going on? Also I tried restarting Unity twice already.

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 phil_me_up · Mar 30, 2016 at 09:06 AM

Are you saying that the Hover and Click function should be executed on the press of a button? These need to be public functions in order for that to happen and properly setup within the Button OnClick component through the Inspector.

If in doubt, use the debugger to make sure they are actually being called or spit out some useful Debug.Log messages (I don't know what you mean that you 'found out by the function name being shown').

Also, remove the empty Start() and Update() functions if they aren't being used. They will just add overhead if they are present (even if empty).

Comment
Add comment · Show 3 · 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 Puffinlump · Mar 30, 2016 at 05:01 PM 0
Share

I tried making the functions public, they now show up in the explorer as I expected them to, but they don't do anything still.

avatar image Puffinlump · Mar 30, 2016 at 05:10 PM 0
Share

I miss typed something :/ your answer was part of the help so I will accept it. (I am an idiot)

avatar image Puffinlump · Mar 30, 2016 at 05:16 PM 0
Share

What I meant by I found out by the function name being shown was when I hovered over the button or clicked it the button was displaying that it was trying to call the functions, but as you can see your answer worked as part of it. It's been a long time since I used C# and Unity.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Argument 1: cannot convert from 'method group' to 'UnityAction' 1 Answer

Problems calling functions from Scriptable Objects 0 Answers

Typing anything anywhere in script ceases all functions? 1 Answer

How to get argument values from persistent listener of UnityEvent 2 Answers

Changing ScrollView content from the script 0 Answers


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