RPG项目01_新输入输出

news2025/1/14 4:21:55

基于“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键拔刀,拔刀后才可以攻击,一直点击鼠标左键执行连击,按空格跳跃,鼠标右键旋转视角。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1281491.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

疫苗接种(链表练习)

很明显&#xff0c;数组也可以做&#xff0c;但是我想练习链表 这道题我上交的时候&#xff0c;同一份代码&#xff0c;三个编译器&#xff0c;三个成绩&#xff0c;有点搞心态 代码如下&#xff1a; #include<stdio.h> #include<math.h> #include<stdlib.h&…

html动漫网页设计分享 紫罗兰永恒花园网页作业成品带视频,注册登录,表格,表单

html5静态网页设计要是用HTML DIVCSS JS等来完成页面的排版设计,一般的网页作业需要融入以下知识点&#xff1a;div布局、浮动、定位、高级css、表格、表单及验证、js轮播图、音频 视频 Flash的应用、ul li、下拉导航栏、鼠标划过效果等知识点&#xff0c;学生网页作业源码可以…

重新认识Word——样式

重新认识Word Word样式给所有一级标题加上一级标题样式修改标题一样式&#xff0c;符合要求 正文样式标题前的小黑点导航窗格样式的相互复制Word一键转PPT 话说回来&#xff0c;一个程序员平时可能还看不起office全家桶的软件&#xff0c;但是&#xff0c;在实际的生活运用中&a…

Elk-filebeat

前言 Elk&#xff1a;filebeat搜集日志工具和logstash相同 Filebeat是一个轻量级的日志收集工具&#xff0c;所使用的资源比logstash部署和启动时使用的资源更小 Filebeat可以运行在非Java环境&#xff0c;他可以代理logstash在非Java环境上收集日志 Filebeat无法实现数据的…

设计基于STM32的温度传感器实时数据采集和显示系统

温度传感器作为常见的传感器之一&#xff0c;被广泛应用于各种领域&#xff0c;如工业自动化、家电控制等。为了实时监测和控制温度&#xff0c;设计一个基于STM32的温度传感器实时数据采集和显示系统是很有必要的。本文将详细介绍如何设计这样一个系统&#xff0c;并提供相应的…

[蓝桥杯 2020 省 AB1] 解码

做题前思路&#xff1a; 1.因为是多组输入&#xff0c;又包含字符于是我们可以先定义一个char类型数组arr 2.定义数组的长度&#xff1a;题目说简写&#xff08;字母加数字&#xff09;长度不超过100&#xff0c;但原来的长度可能超过100&#xff0c;加上小明不会将连续超过9…

英飞凌(Infineon)TC397链接文件解析

本篇文章首先介绍了链接文件在整个代码编译过程中所起到的作用&#xff0c;然后根据TC397芯片对应的链接文件涉及的链接命令&#xff0c;参照官网的示例给出了常见的使用方法&#xff0c;最后分为MEMORY与SECTIONS两个部分以脚本命令走读的形式解析了TC397芯片的链接文件&#…

5_企业架构LNMP高可用负载均衡服务器

企业架构LNMP高可用负载均衡服务器之Nginx 学习目标和内容 1、能够描述负载均衡的作用 2、能够了解负载均衡常见实现方式 3、能够使用Nginx实现负载均衡 4、能够描述Nginx的常见负载均衡算法 一、背景描述及其方案设计 1、业务背景描述 时间&#xff1a;2011.6.-2013.9 发布产…

谈一谈内存对齐

文章目录 一&#xff0c;什么是内存对齐&#xff1f;二&#xff0c;为什么要有内存对齐&#xff1f;三&#xff0c;内存对齐规则&#xff1f; 一&#xff0c;什么是内存对齐&#xff1f; 现代计算机中的内存空间都是按字节划分的&#xff0c;理论上似乎我们对任何类型变量的访…

【iOS控件】—— UIPickerView的使用

【iOS控件】—— UIPickerView的使用 一. 简述UIPickerView1. 什么是UIPickerView2. UIPickerView遵守的协议 二. 测试Demo三. 总结 一. 简述UIPickerView 先看一下UIPickerView的效果图&#xff1a; 1. 什么是UIPickerView UIPickerView是iOS平台上的一个用户界面元素&am…

力扣 --- 最长公共前缀

题目描述&#xff1a; 编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀&#xff0c;返回空字符串 ""。 示例 1&#xff1a; 输入&#xff1a;strs ["flower","flow","flight"] 输出&#xff1a;"fl"…

Windows安装MySQL8.2

Windows安装MySQL8.2 三种安装模式 默认自定义完整 本案例选择自定义 选择安装目录 勾选 Run MySQL Configurator 配置MYSQL 默认为开发者模式 在 Config Type 下拉列表中选择数据中心 设置 root 账号密码

【算法】前后缀分解题单⭐

文章目录 题单来源题目列表42. 接雨水238. 除自身以外数组的乘积2256. 最小平均差2483. 商店的最少代价代码1——前后缀数组代码2—— O ( 1 ) O(1) O(1)空间&#x1f402; 2420. 找到所有好下标2167. 移除所有载有违禁货物车厢所需的最少时间代码1——前后缀分解代码2——简洁…

题目:神奇的进制

解题思路&#xff1a; 用电脑自带的计算器&#xff0c;切换到程序员模式。里面有进制转换功能。 由题目&#xff0c;要求严格递增且都为字母&#xff0c;还要大于2023&#xff0c;则数字16进制为ABC。

wvp gb28181 pro 平台国标级连功能说明

国标28181不同平台之间支持两种连接方式&#xff0c;平级和上下级&#xff0c;WVP目前支持向上级级联。 测试环境 测试平台上级&#xff1a;192.168.10.209&#xff08;Alam centos8&#xff09; 测试平台下级&#xff1a;192.168.10.206&#xff08;ky10_x86&#xff09; 下级…

安装错误_ImportError: cannot import name ‘XXX‘循环引用 绕晕TT(deepsolo)

这里写目录标题 error: Couldnt find a setup script in /tmp/easy_install-lfpvj6p4/scikit_image-0.22.0.tar.gzpip install -v -e . 和 python setup.py develop功能一样吗AttributeError: module ‘PIL.Image’ has no attribute ‘LINEAR’ImportError: cannot import nam…

计算机网络 | 物理层下 传输媒介、信道复用技术,带宽接入技术

文章目录 3. 物理层下面的传输媒介3.1 导引型传输媒介3.2 非导引型传输媒介 4 信道复用技术5 数字传输系统5.1 旧的数字系统5.2 新数字系统 6 带宽接入技术6.1 DSL&#xff08;数字用户线&#xff09;6.2HFC 光纤同轴混合网6.2.1 接入 6.3 FTTx技术 3. 物理层下面的传输媒介 传…

Pandas进阶:拼接 concat 使用方法

1.处理索引和轴 假设我们有2个关于考试成绩的数据集。 df1 pd.DataFrame&#xff08;{ name&#xff1a;[A&#xff0c;B&#xff0c;C&#xff0c;D]&#xff0c;math&#xff1a;[60,89,82,70]&#xff0c;physics&#xff1a;[66&#xff0c; 95,83,66]&#xff0c;chemi…

探究两个互联网时代的差异,Web 2.0 与 Web 3.0 区别

Web 2.0 的特征 首先我们来了解一下 Web 2.0 的特征都有哪些。 用户生成内容&#xff1a;Web 2.0 时代以用户生成内容为特征&#xff0c;用户可以轻松地在网络上分享、创建和编辑信息。社交媒体平台、博客等网站的兴起使得用户成为信息的创造者&#xff0c;网络逐渐从被动浏览…

04-数据库操作对象Statement对象和PreparedStatement对象的区别,SQL注入的优缺点

Statement对象和查询结果集 Statement对象相关的方法 Connection接口中获取数据库操作对象Statement对象的方法 方法名功能Statement createStatement()创建Statement对象 Statement对象执行增删改查的SQL语句(不含占位符"?")的方法,JDBC中的SQL语句不需要提供分…