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 :: c# day of week number 
Csharp :: c# unity detect any keyboard input but not mouse input 
Csharp :: c# shuffle 
Csharp :: how to add a queue unity 
Csharp :: c# unity get name of object 
Csharp :: random.range unity not working 
Csharp :: unity show colliders 
Csharp :: c# latex 
Csharp :: c# 2d list 
Csharp :: c# read authorization header 
Csharp :: c# console wait for input 
Csharp :: replace index in string c# 
Csharp :: What is the difference between String and string in C#? 
Csharp :: c# move files from one folder to another 
Csharp :: c# underscore variable 
Csharp :: c# update control from another thread 
Csharp :: c# contains 
Csharp :: unity how to set rigidbody velocity 
Csharp :: parse datetime c# 
Csharp :: callback function on animation end unity 
Csharp :: c# clamp 
Csharp :: how to look around with mouse in unity 
Csharp :: unity instantiate prefab 
Csharp :: roman to 
Csharp :: unit test c# exception thrown 
Csharp :: c# string interpolation 
Csharp :: c# convert list t to datatable 
Csharp :: delete the particular line in files in c# 
Csharp :: c# get total milliseconds from datetime 
Csharp :: c# distinct array of objects by values 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =