Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my UI button not attaching a function?

I’m trying to achieve a UI like this in my Unity project, where I can use my custom function in a C# script:

here functrion i got in unity 2d

However, instead of the desired UI, I’m getting this on my button:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

desired UI

code (player file c#) :

using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public player player;
    public Text scoreText;
    public GameObject playbutton;
    public GameObject gameoverText;
    private int score;

    void Awake()
    {
        Application.targetFrameRate = 60;
        Pause();
    }
    void Play()
    {
        Debug.Log("Play");
        score = 0;
        scoreText.text = score.ToString();
        Time.timeScale = 1f;
        player.enabled = true;
        playbutton.SetActive(false);
        gameoverText.SetActive(false);

        Pipes[] pipes = FindObjectsOfType<Pipes>();
        foreach (Pipes pipe in pipes)
        {
            Destroy(pipe.gameObject);
        }
    }
    void Pause()
    {
        Time.timeScale = 0f;
        player.enabled = false;

    }
    public void IncreaseScore()
    {
        score++;
        scoreText.text = score.ToString();
    }

    public void Gameover()
    {
        gameoverText.SetActive(true);
        playbutton.SetActive(true);
        Pause();

    }

}

I followed this tutorial on YouTube:
https://www.youtube.com/watch?v=ihvBiJ1oC9U&list=LL&index=2

How can I achieve the first UI style so I can properly attach and use my function in the button?

I’m looking for a solution to display the button with the normal UI appearance, allowing me to integrate it with my C# script.

>Solution :

Your inspector is in Debug mode (right image), set it back to Normal mode (left image) by clicking the [⋮] button in the top right of the inspector tab, and then click "Normal"

enter image description here

Image from Unity – Manual: Working in the Inspector

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading