unity check if key pressed
if (Input.GetKeyDown(KeyCode.KEY))
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;
}
}
how to check to see if the keyboard buttons are pressed in unity
if(Input.GetKey()
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);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us