RPG项目01_新输入输出

基于“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.mzph.cn/news/194541.shtml

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

相关文章

Android把宽高均小于给定值的Bitmap放大到给定值,Kotlin

Android把宽高均小于给定值的Bitmap放大到给定值&#xff0c;Kotlin 假设拉伸放大到SIZE2048 fun scaleSize(image: Bitmap): Bitmap {val w image.widthval h image.heightvar newW: Intvar newH: Intif (w > h) {newW SIZEnewH (SIZE / w.toFloat()) * h} else {newW …

PHP常用系统函数的 学习资料

输出函数 echo($string): 输出一个或多个字符串。print($string): 输出一个字符串。printf($format, $args): 根据指定的格式输出格式化的字符串。var_dump($expression): 打印变量的相关信息&#xff0c;包括类型和值。print_r($expression): 打印变量的易读版本&#xff0c;…

Harmony OS (eTS语言)的起源和演进

Harmony OS&#xff08;eTS语言&#xff09;的起源和演进 1.eTS语言的起源和演进 1.1.概括 Mozilla创造了JS&#xff0c;Microsoft创建了TS&#xff0c;Huawei进一步推出了eTS。eTS&#xff08;extended TypeScript&#xff09;是鸿蒙(Harmony)生态的一种应用开发语言。也是H…

qt 动态生成柱状图

cpp文件 #include "mform.h" #include "ui_mform.h" #include <QBarSeries> #include <QBarSet> #include <QtCharts> #include <QPushButton> #include <QtCharts/QChartView> #include <QtCharts/QPieSeries> #inc…

java中Integer和int有什么区别?

Java中的Integer和int是两种不同的数据类型&#xff0c;主要的区别在于&#xff1a; 1. 基本类型与引用类型&#xff1a;int是基本数据类型&#xff0c;直接存储数值&#xff0c;而Integer是对象&#xff0c;它的实例是引用类型&#xff0c;存储的是对象的引用。 2. 默认值&a…

浅学指针(5)sizeof和strlen的进阶理解

系列文章目录 文章目录 系列文章目录前言1. sizeof和strlen的对⽐1.1 sizeofsizeof不是函数&#xff0c;是运算符 1.2 strlen1.3 sizeof 和 strlen的对⽐ 2. 数组和指针笔试题解析• sizeof(数组名)&#xff0c;sizeof中单独放数组名&#xff0c;这⾥的数组名表⽰整个数组&…

51单片机应用从零开始(九)·数组

目录 1. 用字符型数组控制 P0 口 8 位 LED 流水点亮 2. 用 P0 口显示字符串常量 1. 用字符型数组控制 P0 口 8 位 LED 流水点亮 C语言中的字符型数组是一种数据类型&#xff0c;它是一个由字符组成的序列&#xff0c;以空字符\0结尾。在声明字符型数组时&#xff0c;需要指…

Git【成神路】

目录 1.为啥要学git啊&#xff1f;&#x1f615;&#x1f615;&#x1f615; 2.版本控制软件的基本功能 &#x1f91e;&#x1f91e;&#x1f91e; 3.集中式版本控制 &#x1f936;&#x1f936;&#x1f936; 4.分布式版本控制&#x1f60e;&#x1f60e;&#x1f60e; …

一款自动帮你生成UI界面和代码的AI神器

我的新书《Android App开发入门与实战》已于2020年8月由人民邮电出版社出版&#xff0c;欢迎购买。点击进入详情 只要描述你想要的UI是什么样的&#xff0c;它就能帮你生成&#xff0c;是不是很神奇&#xff1f; v0使用 AI 模型根据简单的文本提示生成用户界面和代码&#xff…

Android 13.0 SystemUI电池电量为0时延迟关机的解决方案

1.简述 在13.0系统rom定制化开发中,在系统开发中可能会遇到了在电池电量为0时这时未出现立即关机的情况,产生延时关机的问题,下面就来分析这个问题所产生的原因,然后解决这个问题 2.SystemUI电池电量为0延迟关机的核心代码 /frameworks/base/services/core/java/com/andr…

含光伏发电的变电站供电系统设计

摘要 面对全球日趋严重的能源危机问题&#xff0c;可再生能源的开发和利用得到了人们的高度重视。其中辐射到地球太阳能资源是十分富饶的&#xff0c;绿色清洁的太阳能不会危害我们的生存环境&#xff0c;因而受到了人们的广泛利用。光伏发电作为可再生能源被广泛的应用&#…

关于在PyTorch中使用cudnn.benchmark= True

关于在PyTorch中使用cudnn.benchmark True 在PyTorch中&#xff0c;cudnn.benchmark True是一个参数&#xff0c;用于启用或禁用cuDNN的基准测试模式。cuDNN是一个由NVIDIA开发的深度神经网络库&#xff0c;它为GPU提供了一个优化的计算接口。 基准测试模式是cuDNN的一个特性…

informer辅助笔记:utils/timefeatures.py

定义了一套与时间特征相关的类和函数&#xff0c;旨在从时间序列数据中提取有用的时间特征&#xff0c;以支持各种时间序列分析和预测任务 from typing import Listimport numpy as np import pandas as pd from pandas.tseries import offsets from pandas.tseries.frequenc…

2023.12.3 分布式SQL查询引擎-Presto

目录 1.Prosto简介 Apache Hadoop-MapReduce Apache Hive 2.Presto的优缺点 3.个人自用启动服务 个人自用启动服务 4.presto和hive的区别 5.presto优化 1.Prosto简介 Apache Hadoop-MapReduce 优点&#xff1a;统一、通用、简单的编程模型&#xff0c;分而治之思想处理…

利用STM32内置温度传感器实现温度监测系统

STM32微控制器是一款强大的嵌入式处理器&#xff0c;具有广泛的应用领域。其中&#xff0c;一些STM32微控制器内置了温度传感器&#xff0c;可以方便地实现温度监测功能。本文将详细介绍如何利用STM32内置温度传感器实现温度监测系统&#xff0c;并提供相应的示例代码。 一、硬…

【算法思考记录】力扣1423. 可获得的最大点数[Java, 滑动窗口]

Problem: 1423. 可获得的最大点数 date: “2023-12-03” 问题重述 正难则反&#xff0c;发挥逆向思维&#xff0c;因为最终无法选择的点数是一个连续区间&#xff0c;所以问题可转换成&#xff1a;在一个给定的数组中&#xff0c;我们需要找到移除长度为 n-k 的子数组后&#…

智慧灯杆系统平台架构设计需要考虑的几个要点

智慧灯杆是一种集成了各种先进技术的道路照明设施。它不仅提供照明服务&#xff0c;还可以具有物联网技术、视频监控、环境监测、广播通讯、无线网络覆盖等多种功能。这些智能功能可以通过互联网进行控制和管理&#xff0c;从而实现智慧城市的建设。智慧灯杆能够提升城市的智能…

Wpf 使用 Prism 实战开发Day07

待办事项页面设计 效果图: 一.布局设计 页面主要分上下布局&#xff0c;分2行进行设计&#xff0c;使用 Grid.RowDefinitions 将页面分上下2行 例如&#xff1a; <Grid.RowDefinitions><RowDefinition Height"auto"/><RowDefinition/> </Gri…

React基本知识点整理

React中引入样式的2种方式 1,内联样式 import React, { Component } from react export default class index extends Component {render() {return (<div><div style{{color:"red",fontSize:"18px"}}>内联样式</div></div>)} }…

Promise自定义封装

目录 Promise构造函数 then方法封装 catch方法封装 resolve方法封装 reject方法封装 all方法封装 race方法封装 这篇文章主要是介绍如何自己封装Promise构造函数以及其相应的方法。Promise是JS中的重点&#xff0c;很多的面试都会问到。因此需要对其有比较深入地认识。看…