Horje
how to check if button is pressed unity Code Example
how to check if button is pressed unity
// Buttons work by adding listeners to the event of their onclick. 
// These listeners can be persistent or runtime listeners. 
// Persistent listeners are assigned in the editor and the runtime 
// listeners are assigned in code at runtime. 
// Here is how you would assign a new listener in code.

public class Controller : MonoBehaviour
{
    [SerializeField] private Button btn = null;

    private void Awake()
    {
        // adding a delegate with no parameters
        btn.onClick.AddListener(NoParamaterOnclick);
           
        // adding a delegate with parameters
        btn.onClick.AddListener(delegate{ParameterOnClick("Button was pressed!");});
    }
    
    private void NoParamaterOnclick()
    {
        Debug.Log("Button clicked with no parameters");
    }
    
    private void ParameterOnClick(string test)
    {
        Debug.Log(test);
    }
}




Csharp

Related
credit card validation in c# Code Example credit card validation in c# Code Example
fakultät berechnen c# Code Example fakultät berechnen c# Code Example
c# array accessor Code Example c# array accessor Code Example
get parent name unity for inspector Code Example get parent name unity for inspector Code Example
c# convert linq jValue to int Code Example c# convert linq jValue to int Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9