“Cómo verificar para ver si los botones del teclado se presionan en Unity” Código de respuesta

Comprobación de la unidad si la tecla se presiona

if (Input.GetKeyDown(KeyCode.KEY))
Excited Elephant

Si se presiona el botón Unidad

    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;
    }
    }
Kevin

Cómo verificar para ver si los botones del teclado se presionan en Unity

if(Input.GetKey()
Poor HUEman

Cómo verificar si se presiona el botón Unidad

// 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);
    }
}
CoderHomie

Respuestas similares a “Cómo verificar para ver si los botones del teclado se presionan en Unity”

Preguntas similares a “Cómo verificar para ver si los botones del teclado se presionan en Unity”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código