R
R
Roman2017-08-20 15:05:58
C++ / C#
Roman, 2017-08-20 15:05:58

How to add the appearance of sprites and buttons on the stage?

Hello!
How to add a sprite with buttons and options inside Unity 2D when clicking on a button? I'm learning C#, but I have no idea how to do it.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Griboks, 2017-08-20
@ananas_roma

OnMouseDown(){someGO.setActive(true);}

D
Daniil Basmanov, 2017-08-20
@BasmanovDaniil

You hang a button in the Canvas , then either subscribe the required method to the click event in the inspector, or do it through a script:

using UnityEngine;
using UnityEngine.UI;

public class Example : MonoBehaviour
{
    public Button button;

    private void Start()
    {
        button.onClick.AddListener(OnClick);
    }

    private void OnClick()
    {
        Debug.Log("Click");
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question