Skip to content

Latest commit

 

History

History
76 lines (63 loc) · 1.33 KB

input.md

File metadata and controls

76 lines (63 loc) · 1.33 KB
title category layout tags prism_languages intro
Input
Events
2017/sheet
Featured
csharp
The Input System for Keyboard, Mouse, Touchpad interactions.

Keyboard

if (Input.GetKeyDown(KeyCode.Space)) { 
    // Space key was Pressed
}
if (Input.GetKeyUp(KeyCode.W)) { 
    //W key was Released
}
if (Input.GetKey(KeyCode.UpArrow)) { 
    // Up Arrow key is being held down 
}
if (Input.GetButtonDown("ButtonName")) { 
    // Button was pressed
}
if (Input.GetButtonUp("ButtonName")) { 
    // Button was released
}
if (Input.GetButton("ButtonName")) { 
    // Button is being held down
}

Button, Mouse & Touch Input located under Edit >> Project Settings >> Input

Mouse

if (Input.GetAxis("Mouse X") < 0) {
    // Mouse moved left
}

if (Input.GetAxis("Mouse Y") > 0) {
    // Mouse moved up
}

if (Input.GetMouseButtonDown(0)) {
    // Pressed primary button.
}

if (Input.GetMouseButtonDown(1)) {
    // Pressed secondary button.
}

if (Input.GetMouseButtonDown(2)) {
    // Pressed middle click.
}

Touch

if (Input.touchCount > 0) {
    touch = Input.GetTouch(0);

    if (touch.phase == TouchPhase.Began) {
        // Touch began
    }

    if (touch.phase == TouchPhase.Moved) {
        // Touch moves
    }

    if (touch.phase == TouchPhase.Ended) {
        // Touch ended
    }
}