0
\$\begingroup\$

I have a simple 2D game, I want a UI button to respawn the character (if it's not already present). The first problem I encountered is that the button only works once. I can't go any further before I solve this, so for now it doesn't spawn anything, I just want it to print debug text every time it's clicked. It only does that once, unfortunately. How do I make it call the function each time I click it?

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class Button_Restart : MonoBehaviour
{
    public Canvas Canvas;

    void Awake()
    {

    }

    public void Restart()
    {
        Debug.Log("Restart button was clicked");
        EventSystem.current.SetSelectedGameObject(null);
    }
}
\$\endgroup\$
1
\$\begingroup\$

Ok I was silly and didn't notice that the console was set to group debug messages together. It is in fact working as intended.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.