c# - 在统一 C# 中,我如何使 moveInput = Input.GetAxis("Horizontal"); 不读取方向键,只检测键盘上的 a 和 d
问题描述
好的,所以我正在制作一个 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;
}
}
解决方案
这取决于您使用的输入系统。假设您使用的是旧系统,请转到编辑 > 项目设置 > 输入。找到“水平”轴并更改您想要的任何键或 alt 键。
推荐阅读
- flutter - 颤振 - 计算:隔离消息中的非法参数:(对象是一个闭包 - 函数'
':.) - flutter - FormatException:方案不以字母字符开头 - Flutter Http Request
- javascript - 用jquery点击重复的div
- graphql - 在 GraphQL 中,如何选择具有相同特征多次出现的条件的字段
- amazon-redshift - postgresql 错误:类型字符变化的值太长(256)
- r - 如何从r中组的所有值中减去最大值
- byte-buddy - JavaConstant.Dynamic.ofInvocation() 中的类型可分配性是否过于严格?
- sustainsys-saml2 - Sustainsys SAML2 如何检索和 RelayState?
- python - 用于下载 PDF 的 Python ( Selenium ) 脚本,当找不到这些脚本时,它会抓取页面以获取类似信息
- python - 将 protobuf 与 bazel 中的 python 命名空间包结合起来