Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

if button is pressed unity

    using UnityEngine;
    using System.Collections;
    using UnityEngine.EventSystems;
     
    public class MyButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
     
    public bool buttonPressed;
     
    public void OnPointerDown(PointerEventData eventData){
         buttonPressed = true;
    }
     
    public void OnPointerUp(PointerEventData eventData){
        buttonPressed = false;
    }
    }
Comment

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);
    }
}
Comment

how to check to see if the keyboard buttons are pressed in unity

if(Input.GetKey()
Comment

PREVIOUS NEXT
Code Example
Csharp :: web.config customerrors not working 
Csharp :: c# switch expression pattern matching 
Csharp :: dctionary literal c# 
Csharp :: c# interface properties 
Csharp :: .net core login redirect loop 
Csharp :: subtract to time c# 
Csharp :: page parent wpf 
Csharp :: c# how to make object rotate forever 
Csharp :: c# sbyte 
Csharp :: if or statement c# 
Csharp :: c# string verbatim 
Csharp :: ef core add OnModelCreating foreign key 
Csharp :: c# convert bitmap to image 
Csharp :: c# multiple exceptions same handler 
Csharp :: c# arrays 
Csharp :: excel rows count 
Csharp :: remove numericUpDown arrows 
Csharp :: js if empty then 0 
Csharp :: c# get enum name from value 
Csharp :: unity move camera to player fluent 
Csharp :: why does everything reset when switching scene unity 
Csharp :: hide component in component menu 
Csharp :: avoid writing the name of the type twice 
Csharp :: C# multiple button click event to textbox 
Csharp :: project camera view to texture 
Csharp :: unity editorwindowtitle obsolete 
Csharp :: Bitwise Left Shift C# 
Csharp :: is list sequential C# 
Csharp :: process method in scala 
Csharp :: cors denied error in asp.net core 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =