基于“RPG项目01_脚本代码”,本次修改unity的新输入输出系统。本次修改unity需要重启,如果一直跟着做教学项目,请先保存项目,再继续修改unity为新输入输出系统。
向下翻,
向下翻,
选择both加入新输入输出系统,此时unity会重新启动。
设置完成加入新输入输出系统
点击包管理器
安装成功
在脚本文件夹Scripts下新建文件夹InputSystem
将New Controls改名为Controls 并将生成脚本打勾 之后应用
即可生成Controls脚本
此时MyPlayer脚本代码中的Controls的注释可以打开了
双击Controls
点击加号起名为MyCtrl
点击加号设置为一轴的
设置完成
继续设置下一个按键
设置完成
保存
修改MyPlayer代码:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
SetInput();
}
void Update() {
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
}
运行即可实现按键盘w/s键实现跑步松开即停止
接下来添加跳跃:
修改MyPlayer代码:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
SetInput();
}
void Update() {
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
}
即实现
按空格键Space跳跃
接下来设置旋转
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
SetInput();
}
void Update() {
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
action.MyCtrl.Rotate.started += Rotate;
action.MyCtrl.Rotate.performed += Rotate;
}
private void Rotate(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
rvalue = context.ReadValue<float>();
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
private void FastSpeed(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") || Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
{
if (context.phase == InputActionPhase.Canceled)
{
spdFast = 1;
}
else
{
spdFast = 2;
}
}
}
}
接下来设置速度
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
SetInput();
}
void Update() {
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
action.MyCtrl.Rotate.started += Rotate;
action.MyCtrl.Rotate.performed += Rotate;
action.MyCtrl.Fast.started += FastSpeed;
action.MyCtrl.Fast.performed += FastSpeed;
action.MyCtrl.Fast.canceled += FastSpeed;
}
private void FastSpeed(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
{
if (context.phase == InputActionPhase.Canceled)
{
spdFast = 1;
}
else
{
spdFast = 2;
}
}
}
private void Rotate(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
rvalue = context.ReadValue<float>();
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
}
设置获取道具
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
SetInput();
}
void Update() {
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
action.MyCtrl.Rotate.started += Rotate;
action.MyCtrl.Rotate.performed += Rotate;
action.MyCtrl.Fast.started += FastSpeed;
action.MyCtrl.Fast.performed += FastSpeed;
action.MyCtrl.Fast.canceled += FastSpeed;
action.MyCtrl.GetTool.started += ClickNpcAndTool;
}
private void ClickNpcAndTool(InputAction.CallbackContext context)
{
//throw new NotImplementedException();
}
private void FastSpeed(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
{
if (context.phase == InputActionPhase.Canceled)
{
spdFast = 1;
}
else
{
spdFast = 2;
}
}
}
private void Rotate(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
rvalue = context.ReadValue<float>();
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
}
添加输入系统:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
//获取自身角色控制器
contro = GetComponent<CharacterController>();
SetInput();
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
action.MyCtrl.Rotate.started += Rotate;
action.MyCtrl.Rotate.performed += Rotate;
action.MyCtrl.Fast.started += FastSpeed;
action.MyCtrl.Fast.performed += FastSpeed;
action.MyCtrl.Fast.canceled += FastSpeed;
action.MyCtrl.GetTool.started += ClickNpcAndTool;
action.MyCtrl.HoldRotate.performed += Hold;
action.MyCtrl.HoldRotate.canceled += Hold;
}
private void Hold(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (context.phase == InputActionPhase.Canceled)
{
isHold = false;
}
else
{
isHold = true;
}
}
private void ClickNpcAndTool(InputAction.CallbackContext context)
{
//throw new NotImplementedException();
}
private void FastSpeed(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
{
if (context.phase == InputActionPhase.Canceled)
{
spdFast = 1;
}
else
{
spdFast = 2;
}
}
}
private void Rotate(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
rvalue = context.ReadValue<float>();
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
void Ctrl()
{
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle")||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight")){
float f = action.MyCtrl.Move.ReadValue<float>();
contro.Move(transform.forward * f * Time.deltaTime * spdFast * Spd);
contro.Move(transform.up * -9.8f * Time.deltaTime);
if (isHold)
{
transform.Rotate(transform.up * rvalue * 0.3f);
}
}
}
void Update()
{
if (GameManager.gameState != GameState.Play)
{
return;
}
Ctrl();
}
}
修改MyPlayer代码:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
//获取自身角色控制器
contro = GetComponent<CharacterController>();
SetInput();
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
action.MyCtrl.Rotate.started += Rotate;
action.MyCtrl.Rotate.performed += Rotate;
action.MyCtrl.Fast.started += FastSpeed;
action.MyCtrl.Fast.performed += FastSpeed;
action.MyCtrl.Fast.canceled += FastSpeed;
action.MyCtrl.GetTool.started += ClickNpcAndTool;
}
private void ClickNpcAndTool(InputAction.CallbackContext context)
{
//throw new NotImplementedException();
}
private void FastSpeed(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
{
if (context.phase == InputActionPhase.Canceled)
{
spdFast = 1;
}
else
{
spdFast = 2;
}
}
}
private void Rotate(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
rvalue = context.ReadValue<float>();
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
void Ctrl()
{
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle")||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight")){
float f = action.MyCtrl.Move.ReadValue<float>();
contro.Move(transform.forward * f * Time.deltaTime * spdFast * Spd);
contro.Move(transform.up * -9.8f * Time.deltaTime);
if (isHold)
{
transform.Rotate(transform.up * rvalue * 0.3f);
}
}
}
void Update()
{
if (GameManager.gameState != GameState.Play)
{
return;
}
Ctrl();
}
}
即可实现人物前后移动:
继续设置拔剑
设置攻击
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
//获取自身角色控制器
contro = GetComponent<CharacterController>();
SetInput();
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
action.MyCtrl.Rotate.started += Rotate;
action.MyCtrl.Rotate.performed += Rotate;
action.MyCtrl.Fast.started += FastSpeed;
action.MyCtrl.Fast.performed += FastSpeed;
action.MyCtrl.Fast.canceled += FastSpeed;
action.MyCtrl.GetTool.started += ClickNpcAndTool;
action.MyCtrl.HoldRotate.performed += Hold;
action.MyCtrl.HoldRotate.canceled += Hold;
action.MyAtt.Att.started += Attack;
}
private void Attack(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight"))
{
Anim.SetInteger("Att", 1);
Anim.SetTrigger("AttTrigger");
}
else
{
int num = Anim.GetInteger("Att");
if (num == 6)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Light_Attk_" + num))
{
Anim.SetInteger("Att", num + 1);
}
}
}
public void PlayerAttack(string hurt)
{
Collider[] cs = Physics.OverlapBox(attPoint.position, Vector3.one * 0.5f,
attPoint.rotation, LayerMask.GetMask("Enemy"));
if (cs.Length <= 0)
{
return;
}
int value = (int)(Att * Anim.GetInteger("Att") * 0.5f);
foreach (Collider c in cs)
{
print(value);
}
}
public void PlayerAttackHard(string hurt)
{
Collider[] cs = Physics.OverlapBox(attPoint.position, Vector3.one * 0.5f,
attPoint.rotation, LayerMask.GetMask("Enemy"));
if (cs.Length <= 0)
{
return;
}
int value = (int)(Att * Anim.GetInteger("Att") * 0.5f);
foreach (Collider c in cs)
{
print(value);
print("让敌人播放击倒特效");
}
}
private void Hold(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (context.phase == InputActionPhase.Canceled)
{
isHold = false;
}
else
{
isHold = true;
}
}
private void ClickNpcAndTool(InputAction.CallbackContext context)
{
//throw new NotImplementedException();
}
private void FastSpeed(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
{
if (context.phase == InputActionPhase.Canceled)
{
spdFast = 1;
}
else
{
spdFast = 2;
}
}
}
private void Rotate(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
rvalue = context.ReadValue<float>();
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
void Ctrl()
{
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle")||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight")){
float f = action.MyCtrl.Move.ReadValue<float>();
contro.Move(transform.forward * f * Time.deltaTime * spdFast * Spd);
contro.Move(transform.up * -9.8f * Time.deltaTime);
if (isHold)
{
transform.Rotate(transform.up * rvalue * 0.3f);
}
}
}
void Update()
{
if (GameManager.gameState != GameState.Play)
{
return;
}
Ctrl();
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class MyPlayer : People{
[Header("==============子类变量==============")]
public Transform toolPanel;//道具面板
public Transform skillPanel;//技能面板
//public BagPanel bag;//背包
CharacterController contro;
Controls action;
float rvalue;
float spdFast = 1;
bool isHold;//握刀
GameObject sword;
GameObject swordBack;
public Image imageHp;
public Image imageMp;
new void Start() {
base.Start();
//获取自身角色控制器
contro = GetComponent<CharacterController>();
SetInput();
}
void SetInput(){
action = new Controls();
action.Enable();
action.MyCtrl.Move.started += Move;
action.MyCtrl.Move.performed += Move;
action.MyCtrl.Move.canceled += StopMove;
action.MyCtrl.Jump.started += Jump;
action.MyCtrl.Rotate.started += Rotate;
action.MyCtrl.Rotate.performed += Rotate;
action.MyCtrl.Fast.started += FastSpeed;
action.MyCtrl.Fast.performed += FastSpeed;
action.MyCtrl.Fast.canceled += FastSpeed;
action.MyCtrl.GetTool.started += ClickNpcAndTool;
action.MyCtrl.HoldRotate.performed += Hold;
action.MyCtrl.HoldRotate.canceled += Hold;
action.MyAtt.Att.started += Attack;
action.MyAtt.SwordOut.started += SwordOut;
}
private void SwordOut(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
Anim.SetBool("SwordOut", !Anim.GetBool("SwordOut"));
}
private void Attack(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight"))
{
Anim.SetInteger("Att", 1);
Anim.SetTrigger("AttTrigger");
}
else
{
int num = Anim.GetInteger("Att");
if (num == 6)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Light_Attk_" + num))
{
Anim.SetInteger("Att", num + 1);
}
}
}
public void PlayerAttack(string hurt)
{
Collider[] cs = Physics.OverlapBox(attPoint.position, Vector3.one * 0.5f,
attPoint.rotation, LayerMask.GetMask("Enemy"));
if (cs.Length <= 0)
{
return;
}
int value = (int)(Att * Anim.GetInteger("Att") * 0.5f);
foreach (Collider c in cs)
{
print(value);
}
}
public void PlayerAttackHard(string hurt)
{
Collider[] cs = Physics.OverlapBox(attPoint.position, Vector3.one * 0.5f,
attPoint.rotation, LayerMask.GetMask("Enemy"));
if (cs.Length <= 0)
{
return;
}
int value = (int)(Att * Anim.GetInteger("Att") * 0.5f);
foreach (Collider c in cs)
{
print(value);
print("让敌人播放击倒特效");
}
}
private void Hold(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (context.phase == InputActionPhase.Canceled)
{
isHold = false;
}
else
{
isHold = true;
}
}
private void ClickNpcAndTool(InputAction.CallbackContext context)
{
//throw new NotImplementedException();
}
private void FastSpeed(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
{
if (context.phase == InputActionPhase.Canceled)
{
spdFast = 1;
}
else
{
spdFast = 2;
}
}
}
private void Rotate(InputAction.CallbackContext context)
{
if (GameManager.gameState != GameState.Play)
{
return;
}
rvalue = context.ReadValue<float>();
}
private void Jump(InputAction.CallbackContext obj){
Anim.SetTrigger("Jump");
}
private void StopMove(InputAction.CallbackContext context){
Anim.SetBool("IsRun", false);
}
private void Move(InputAction.CallbackContext context){
if (GameManager.gameState != GameState.Play) {
return;
}
Anim.SetBool("IsRun", true);
}
void Ctrl()
{
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace") ||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle")||
Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight")){
float f = action.MyCtrl.Move.ReadValue<float>();
contro.Move(transform.forward * f * Time.deltaTime * spdFast * Spd);
contro.Move(transform.up * -9.8f * Time.deltaTime);
if (isHold)
{
transform.Rotate(transform.up * rvalue * 0.3f);
}
}
}
void Update()
{
if (GameManager.gameState != GameState.Play)
{
return;
}
Ctrl();
}
}
在运行前将手中刀隐藏
运行按E键拔刀后鼠标左键点击即实现连招
具体操作:运行后w/s键前后移动,按E键拔刀,拔刀后才可以攻击,一直点击鼠标左键执行连击,按空格跳跃,鼠标右键旋转视角。