UNITY精细学习2
Player 人物创建
1.Add Component 为对象添加组件
-
Physics 2D -> 重力组键 Reigidbody 2D -> Body Type:Static 固定场景 Constrains 固定旋转
-> 人物碰撞体积 Capsule Collider 2D
-> 瓦片碰撞体 Tile map Collider 2D
-> 组合瓦片碰撞体 Composite Collider 2D
-
Add Component ->对应代码文件
2.创建及配置新输入系统
Edit -> project sittings -> player -> other sittings
-> Api :.NET Framework
creat -> Active Input -> (New)
Action Type (Value)
Control Type (Vector 2)
为角色添加输出系统
(1)直接为角色添加输入组件 (Player Input) -> creat Actrion
(2)代码形式使用 -> Generate C# Class 勾选 ->编辑playerController
using UnityEngine.inputSysteam; //调用输入系统
//再主类中创建调用控制
public PlayerInputController inputControl;
//创建描述量 PS:类型与输入系统的一致
public Vector2 inputDirection;
//启动时执行的函数
private void Awake()
{
//初始化输入系统
inputControl = new PlayerInputController();
}
//开始时启动,停止时关闭
private void OnEnable()
{
inputControl.Enable();
}
private void OnDisable()
{
inputControl.Disable();
}
//每一帧时更新
private void Update()
{
//获取详细位置
inputDirection = inputControl.Gameplayer.Move.ReadValue<Vector2>();
}
浙公网安备 33010602011771号