Input accesses the interface class of the input system in unity

Input accesses the interface class of the input system

Continuous detection (movement)

public class No8_Input : MonoBehaviour
{
    
    

    void Update()
    {
    
    
        //连续检测(移动)
        print("当前玩家输入的水平方向的轴值是:" + Input.GetAxis("Horizontal"));//输出渐变从0到1或0到-1的过程,步频是0.05
        print("当前玩家输入的垂直方向的轴值是:" + Input.GetAxis("Vertical"));

        print("当前玩家输入的水平方向的边界轴值是:" + Input.GetAxisRaw("Horizontal"));//输出值只有0,1,-1,无渐变过程
        print("当前玩家输入的垂直方向的边界轴值是:" + Input.GetAxisRaw("Vertical"));
        
        print("当前玩家鼠标水平移动增量是:" + Input.GetAxis("Mouse X"));
        print("当前玩家鼠标垂直移动增量是:" + Input.GetAxis("Mouse Y"));
    }
}

Continuous detection (event)

Determine the keys that the player continues to press, such as holding down the left mouse button and continuing to fire.

    void Update()
    {
    
    
        if (Input.GetButton("Fire1"))
        {
    
    
            print("当前玩家正在使用武器1进行攻击!");
        }

        if (Input.GetMouseButton(0))
        {
    
    
            print("当前玩家按住鼠标左键");
        }

        if (Input.GetButton("Fire2"))
        {
    
    
            print("当前玩家正在使用武器2进行攻击!");
        }

        //通过Edit -> Settings -> Input修改一个按键名称为RecoverSkill
        if (Input.GetButton("RecoverSkill"))
        {
    
    
            print("当前玩家使用了恢复技能回血!");
        }
    }

interval detection (event)

    void Update()
    {
    
    
        //按下时,Down
        if (Input.GetButtonDown("Jump"))
        {
    
    
            print("当前玩家按下跳跃键");
        }
        if (Input.GetKeyDown(KeyCode.Q))
        {
    
    
            print("当前玩家按下Q键");
        }
        if (Input.anyKeyDown)
        {
    
    
            print("当前玩家按下了任意一个按键,游戏开始");
        }
        if (Input.GetMouseButtonDown(1))
        {
    
    
            print("当前玩家按下鼠标右键");
        }
        //抬起时,Up
        if (Input.GetMouseButtonUp(2))
        {
    
    
            print("当前玩家抬起鼠标中键(从按下状态松开滚轮)");
        }
    }

Guess you like

Origin blog.csdn.net/qq_43007056/article/details/130812405