C# 在unity C中,“如何使moveInput=Input.GetAxis(”水平“);不读取箭头键,仅检测键盘上的a和d

C# 在unity C中,“如何使moveInput=Input.GetAxis(”水平“);不读取箭头键,仅检测键盘上的a和d,c#,unity3d,C#,Unity3d,好的,我正在做一个metroidvania,我在代码中使用了一些简单的输入,但是我想用箭头键来表示特殊能力,用wasd键来表示移动。当我使用我的代码时,它读取wasd和箭头键。如何使其仅检测wasd而不检测箭头键?请帮忙!这是我的密码: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerControler : MonoBehaviour { publ

好的,我正在做一个metroidvania,我在代码中使用了一些简单的输入,但是我想用箭头键来表示特殊能力,用wasd键来表示移动。当我使用我的代码时,它读取wasd和箭头键。如何使其仅检测wasd而不检测箭头键?请帮忙!这是我的密码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControler : MonoBehaviour
{
public float speed;
public float jumpforce;
private float moveInput;

private Rigidbody2D rb;

private bool facingRight = true;

private bool isGrounded;
public Transform GroundCheck;
public float checkRadius;
public LayerMask whatIsground;

private int extraJumps;
public int extraJumpsValue;

void Start()
{
    extraJumps = extraJumpsValue;
    rb = GetComponent<Rigidbody2D>();
}

void FixedUpdate()
{


    moveInput = Input.GetAxis("Horizontal");
    rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

    if(facingRight == false && moveInput > 0)
    {
        Flip();
    }else if(facingRight == true && moveInput < 0)
    {
        Flip();
    }
}

void Update()
{
    isGrounded = Physics2D.OverlapCircle(GroundCheck.position, checkRadius, whatIsground);

    if (isGrounded == true)
    {
        extraJumps = extraJumpsValue;
    }

    if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps > 0)
    {
        rb.velocity = Vector2.up * jumpforce;
        extraJumps--;
    }else if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && isGrounded == true)
    {
        rb.velocity = Vector2.up * jumpforce;
    }
}

void Flip()
{
    facingRight = !facingRight;
    Vector3 Scaler = transform.localScale;
    Scaler.x *= -1;
    transform.localScale = Scaler;
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共级玩家控制器:单一行为
{
公众浮标速度;
公共安全部队;
私有浮点输入;
私有刚体2d rb;
私有bool-facingRight=true;
私人学校停课;
公开审查;
公共浮动校验半径;
公共层码头;
私家车;
公共价值;
void Start()
{
extraJumps=extraJumpsValue;
rb=GetComponent();
}
void FixedUpdate()
{
moveInput=Input.GetAxis(“水平”);
rb.velocity=新矢量2(移动输入*速度,rb.velocity.y);
if(facingRight==false&&moveInput>0)
{
翻转();
}else if(facingRight==true&&moveInput<0)
{
翻转();
}
}
无效更新()
{
IsGround=Physics2D.重叠圆(GroundCheck.position,checkRadius,whatIsground);
如果(isGrounded==真)
{
extraJumps=extraJumpsValue;
}
if(Input.GetKeyDown(KeyCode.UpArrow)&&extraJumps>0)
{
rb.速度=矢量2.向上*跳跃力;
额外跳跃--;
}else if(Input.GetKeyDown(KeyCode.UpArrow)&&extraJumps==0&&isground==true)
{
rb.速度=矢量2.向上*跳跃力;
}
}
void Flip()
{
facingRight=!facingRight;
Vector3 Scaler=transform.localScale;
Scaler.x*=-1;
transform.localScale=Scaler;
}

}这取决于您使用的输入系统。假设您使用的是旧系统,请转至编辑>项目设置>输入。找到“水平”轴并更改您想要的任何键或alt键。

谢谢您的救命恩人!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!没问题,但仅供参考,你不应该评论感谢他人,因为评论是为了解决问题或得到澄清。向上投票并将答案标记为最佳答案是堆栈溢出中的一件大事。请在此处阅读更多信息: