目录

安装InputSystem

在编辑的脚本中使用 InputSystem生成的脚本


Unity版本:2019.2.3f1

安装InputSystem

菜单栏/Window/Package Manager/Input System

工程面板内 右键-->创建Input Actions 

选中New Controls改名为PlayerControls 然后属性 面板按下Edit asset

Action Maps添加:PlayerMovement

Actions添加:New action 改名为MovementAction

Properties项    修改ActionType=Pass Through

修改ControlType= Vector2

在MovementAction项点击+号 选择Add 2D Vector Composite

生成WASD

绑定Up、Down、Left、Right,如此类推

回到PlayerControls属性面板 勾选Generate C# Class[*]

工程面板就生成了一份 PlayerControls.cs 脚本 

在编辑的脚本中使用 InputSystem生成的脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class PlayerLocomotion : MonoBehaviour
{PlayerControls inputActions;//声明 InputSystem的脚本对象public new Rigidbody rigidbody;Vector2 movementInput;//存储 WASD输入的值[Header("Stats")][SerializeField]float movementSpeed = 5;// Start is called before the first frame updatevoid Start(){rigidbody = GetComponent<Rigidbody>();}// Update is called once per framevoid Update(){Vector3 vector3 = new Vector3(movementInput.x * movementSpeed, 0, movementInput.y * movementSpeed);rigidbody.velocity = vector3;//给刚体 这个方向的速度}public void OnEnable(){//获取设备上的输入if (inputActions==null){inputActions = new PlayerControls();//绑定输入的值inputActions.PlayerMovement.MovementAction.performed += outputActions => movementInput = outputActions.ReadValue<Vector2>();}inputActions.Enable();//启用}public void OnDisable(){inputActions.Disable();//禁用}
}

\

完成

Unity简单操作:InputSystem获取WASD键盘输入 移动人物相关推荐

  1. Unity自学笔记——Day01_实现WASD键盘控制移动人物和镜头跟随

    1.键盘移动控制: using System.Collections; using System.Collections.Generic; using UnityEngine;public class ...

  2. Android获取软键盘输入内容

    该功能的实现是通过Android辅助功能来进行实现的, 先上效果图:                                                      下面说一下如何使用Acc ...

  3. Unity3D基础9:获取鼠标键盘输入

    前文:https://blog.csdn.net/Jaihk662/article/details/86751079(C#脚本) 一.获取键盘输入 相关API(其中KeyCode为键码,例如空格键就是 ...

  4. Unity简单操作: 监听粒子系统播放完毕——OnParticleSystemStopped函数

    OnParticleSystemStopped OnParticleSystemStopped是MonoBehaviour中有监听当前物体所挂在粒子系统停止时调用的函数.官方API点这里查看. 使用方 ...

  5. Unity简单操作:HDR(一) 给Camera开启HDR

  6. Unity简单操作:Unity 里使用Gif图片

    参考http://wiki.unity3d.com/index.php/AnimatedGifDrawer. 原理是:将gif图拆分成多个单个图片,用Texture2D存放,然后逐个替换Texture ...

  7. Unity简单操作:设置触发条件 切换Animator动画控制器 里面播放的Animation动画

    确保animator里面有多个animation动画剪辑,点击Animator里面[Parameters]添加触发条件 添加连线箭头并且 给箭头连线绑定触发事件 添加连线箭头并且 给箭头连线绑定触发事 ...

  8. java 获取键盘输入法_Java中接收键盘输入的三种方法

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  9. java中像scanf一样多个输入_VB模拟键盘输入的N种方法

    VB模拟键盘输入的N种方法http://bbs.csdn.net/topics/90509805hd378发表于: 2006-12-24 14:35:39用VB模拟键盘事件的N种方法 键盘是我们使用计 ...

最新文章

  1. 哈希表的详细介绍 -转载
  2. python爬虫能干什么-Python爬虫可以做什么?
  3. libevent在windows下使用步骤详解
  4. linux下安装mysql的方式_linux下安装mysql的两种方式
  5. C/C++ 之 C++强制类型转换(static_cast、dynamic_cast、const_cast、reinterpret_cast)
  6. 电脑用电量_闲置电脑也能赚钱?「BOINC算力地球」借区块链技术扩大共享算力...
  7. 深入浅出聊聊Kubernetes存储(二):搞定持久化存储
  8. 优化了MYSQL大量写入问题,老板奖励了1000块给我
  9. 微信支持导出头像、手机号等个人信息!网友:这就是微信的“个人简历”?...
  10. Flink-org.apache.flink.streaming.api.windowing.windows.Window
  11. animate inater插件_maya插件管理器(Plug-in Manager),MAYA
  12. 用LM方法的matlab求解,matlab中LM算法
  13. 多元统计分析基于r课后答案_(完整版)多元统计分析课后练习答案
  14. windows异常捕获生成minidump windows
  15. 如何可以用cad迷你家装v2018
  16. 【Oracle】IF EXISTS用法
  17. 大麦网抢票软件工具开发系列(一)
  18. IOS 控制器切换的动画样式
  19. Python爬虫实战 | 人民网爬虫 根据关键词筛选新闻文章
  20. stata判断变量是不是唯一标识的命令?

热门文章

  1. editthiscookie最详细安装到浏览器方法
  2. linux编译boost配置codeblocks,Ubuntu 14.04下CodeBlocks手动编译配置Bost 1.57.0
  3. 怎么用手机制作一个四格漫画(flutter)
  4. 百度地图API-地图初始化及初步使用
  5. linux python2.7 protobuf_python2.7protobuf.py文件生成issu
  6. C#+SQLServer餐饮管理系统源码
  7. pd.Series()函数解析(最清晰的解释)
  8. 如何使用物联网卡以及其作用
  9. qt绘画扇形drawPie()和反着三角函数qAcos()
  10. 神卓互联是一款无需端口映射内网穿透软件