unity学习笔记(Input类)

鼠标输入

  • 当指定的鼠标按钮被按下时返回true
    bool result=Input.GetMouseButton(0);

  • 在用户按下指定鼠标按键的第一帧返回true
    bool result=Input.GetMouseButtonDown(0);

  • 在用户释放指定鼠标按键的第一帧返回true
    bool result=Input GetMouseButtonUp(0);

  • 按钮值设定:
    0对应左键,1对应右键,2对应中键。

键盘输入

  • 当通过名称指定的按键被用户按住时返回true
    bool result=Input.GetKey(KeyCode.A);
  • 当用户按下指定名称按键时的那一帧返回true
    bool result=Input.GetkeyDown(KeyCode.A);
  • 在用户释放给定名称按键的那一帧返回true
    bool result=Input.GetkeyUp(KeyCode.A);

如何判断同时按下多个键位:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 
/// </summary>
public class TestInput : MonoBehaviour
{
    public bool isDown;
    private void Update()
    {
    	//同时按下WQ键
        if(Input.GetKey(KeyCode.W)&&Input.GetKeyDown(KeyCode.Q))
            Debug.Log("WQ");
    }
}

Mathf.Lerp

插值运算

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 
/// </summary>
public class TestInput : MonoBehaviour
{
    private float InitialData;
    public bool IsDown;
    private Camera camera;

    private void Start()
    {
        camera = GetComponent<Camera>();
        InitialData = camera.fieldOfView;
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            IsDown = !IsDown;
        }
        if (IsDown)
        {
            camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, 20, 0.1f);
        }
        else
            camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, 60, 0.1f);
    }

}

Mathf.Lerp(起点,终点,百分比);
Lerp

InputManager

什么是InputManager?
·即输入管理器Edit-Project Settings-Input
·使用脚本通过虚拟轴名称获取自定义键的输入。
·玩家可以在游戏启动时根据个人喜好对虚拟轴进行修改。

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值