unity 播放器向后移动(新输入系统)

问题描述 投票:0回答:0

错误视频 你好 我是游戏开发的巴西学生(我的英语很糟糕抱歉)。

我正在制作一个二维平台游戏来测试统一代码。最初该项目使用原始输入管理系统,但我想测试新的输入系统。 实施新的输入系统后,当我跳跃并撞到墙上时,玩家角色正在向后移动。

那是我的播放器脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Haptics;
using UnityEngine.UI;
 
public class Player : MonoBehaviour
{
    // Variavel que recebe se um valor de pulo foi acionado.    
    private bool _pular = false; 
    [SerializeField]
    // velocidade de movimento
    public float _speed = 5f; 
    [SerializeField]
    // Força do pulo
    private float _jump;
    // Componente Rigdbody2D  
    private Rigidbody2D rig;  
    private bool isJumping; 
    private bool doublejump; 
    // Componente Animator
    private Animator anim;  
    private float auxJump; 
    private float auxMove; 
    private float auxMoveSpeed;
    private float auxJumpSpeed; 
    [SerializeField] private SelecaoSkin skin; 
    [SerializeField] private Sprite sprite; 
 
    private void Start()
    {
        // Importando o componente Rigidbody 2d para o script
        rig = GetComponent<Rigidbody2D>(); 
        // Importando o componente Animator para o script
        anim = GetComponent<Animator>();  
        changeSkin();
    } 
    private void Update()
    {
        // move(); // Movimento
        // jump(); // Pulo 
        if (transform.position.y <= -36)
        { 
            transform.position = new Vector2(-17.56f, -22.0f); 
        } 
    }   
    public void move(InputAction.CallbackContext value) 
    {       
        auxMove = value.ReadValue<float>();       
        rig.velocity = new Vector2(auxMove * _speed, rig.velocity.y); 
        if (auxMove > 0)
        {
            auxMove = 1;
            transform.eulerAngles = new Vector3(0, 0, 0);
            anim.SetBool("walk", true);
        }        
        else if (auxMove < 0)
        {
            auxMove = -1; 
            transform.eulerAngles = new Vector3(0, 180, 0);
            anim.SetBool("walk", true); 
        }
        else if (auxMove == 0)
        {
            anim.SetBool("walk", false);
        }
    } 
    public void jump(InputAction.CallbackContext value) 
    { 
        _pular = value.performed; 
        if(_pular)
        {
            if (!isJumping)
            {
                Gamepad.current.SetMotorSpeeds(0.25f, 0.75f);
                isJumping = true;
                //auxJump--;
                anim.SetBool("jump", true);
                rig.AddForce(new Vector2(0f, _jump), ForceMode2D.Impulse);
                doublejump = true;
                _pular = false;
            }
            else if (doublejump)
            {
                Gamepad.current.SetMotorSpeeds(0.25f, 0.75f); 
                // auxJump--; 
                doublejump = false; 
                rig.AddForce(new Vector2(0f, _jump), ForceMode2D.Impulse);
                _pular = false; 
            }
        } 
    } 
        private void OnCollisionEnter2D(Collision2D other)
        {
            if (other.gameObject.layer == 6)
            {
                GameControler.instance.GameOver();
                Destroy(this.gameObject);
            }
 
            if (other.gameObject.layer == 3)
            {
                isJumping = false;
                anim.SetBool("jump", false); 
            }
        } 
        private void OnitCollisionExit2D(Collision2D other)
        {
            // se o objeto colidido estiver na camada 3(chao)            
            if (other.gameObject.layer == 3) 
            {
                isJumping = true; // Definindo isJumping como verdadeiro
            }
        }
        // Sistema de troca de skin     
        public void changeSkin() 
        {
            if (GameControler.playerSkin != null)
            {
                skin = GameControler.playerSkin;
            } 
            anim.runtimeAnimatorController = skin.animControler; 
            sprite = skin.sprite; 
        }
}
 

我正在创建一个玩家移动和跳跃的功能,玩家应该在按下按钮的方向上正常移动,但如果我撞到墙上并跳跃,玩家会向后移动。

c# unity3d unityscript
© www.soinside.com 2019 - 2024. All rights reserved.