- Home /
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.
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).
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.
I miss typed something :/ your answer was part of the help so I will accept it. (I am an idiot)
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
![](https://koobas.hobune.stream/wayback/20220612073804im_/https://answers.unity.com/themes/thub/images/avi.jpg)