Hello!
I’m new to the Unity sphere and currently developing my first game. I’m experiencing an issue and seeking help.
I want to create a new UI for my game to have a screen before the game starts. However, when I try to assign functions to my buttons, I always receive the same response: “No function” or “MonoScript”. I can’t find the functions my code is supposed to provide, even when I try in a brand new project, the result is the same. I also tried using an older version, but the same issue persists.
If anyone has encountered a similar problem or knows how to resolve it, I’m interested!
Thank you!
You may need to show some script you are referencing, but i wonder, are the methods in the script exposed so that the inspector can see them,?
Yeah, heres the code I tried to use :
using UnityEngine;
using UnityEngine.SceneManagement; // For loading scenes
public class MainMenu : MonoBehaviour
{
// This function is called when the “Play” button is pressed
public void PlayGame()
{
// Replace “GameScene” with the name of your game scene
SceneManager.LoadScene(“GameScene”);
}
// This function is called when the "Options" button is pressed
public void Options()
{
// Display the options menu
Debug.Log("Options");
}
// This function is called when the "Quit" button is pressed
public void QuitGame()
{
Application.Quit();
Debug.Log("Quit the game");
}
}
Are you dragging the script from the project panel or have you attached the script as a component to a gameobject in the scene and dragging that into the button?
From what I know you cant reference a script like that from assets and the script must be in the scene. You can create an empty gameobject called scripts or whatever you want to name it, then add component and add your script then drag that gameobject into the button and youll be able to find the script and select the function
Yeah, I tried this. I put the script into an empty GameObject, and then manually dragged the code into the space and selected it manually also, but it didn’t work either way. I tried on another computer and the problem is still the same. I think it may be the code. I used an AI to write it and don’t know if that’s the problem.
The script can be recognized by the inspector, but not the function. I helped a classmate with her UI, and she didn’t have any issues.
Ok, I got it! I dragged the script and not the GameObject!!!
Thank you, guys, for hearing my pain :')