Answer the question
In order to leave comments, you need to log in
Calling a function from another script?
When creating the Start and Restart buttons, which will appear either at the beginning of the game, and when losing, respectively. Essence of the question - When creating a script, and calling a function from another script in the script, and when calling OnClick on the button, an error occurs:
NullReferenceException: Object reference not set to an instance of an object
PokeyBallTest.Controller.ButtonController.RestartCanvas () (at Assets/Scripts/Controller/ButtonController.cs:20)
UnityEngine.Events.InvokableCall.Invoke () (at :0)
UnityEngine.Events.UnityEvent.Invoke () (at :0) and there's a lot more text...
I will attach a script, tell me how to implement my plan. Thank you!
public class ButtonController : MonoBehaviour
{
public GameObject ButtonLose;
private PlayerController btnLose;
private void Start()
{
btnLose = ButtonLose.GetComponent<PlayerController>();
}
public void RestartCanvas()
{
btnLose.RestartPlayer();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question