【发布时间】:2020-09-09 10:22:03
【问题描述】:
有人可以告诉我这段代码有什么问题,但我的播放器飞到了天空。 我刚开始编码,但请帮助我。
这段代码的开头从这里开始:
using System.Collections;
使用 System.Collections.Generic; 使用 UnityEngine;
公共类 PlayerController : MonoBehaviour {
private Rigidbody2D rb;
public float speed;
public float jumpForce;
private float moveInput;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
private float jumpTimeCounter;
public float jumpTime;
private bool isJumpimg;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
void Update()
{
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
isJumpimg = true;
jumpTimeCounter = jumpTime;
rb.velocity = Vector2.up * jumpForce;
{
}
if (Input.GetKey(KeyCode.Space) && isJumpimg == true)
if (jumpTimeCounter > 0)
{
rb.velocity = Vector2.up * jumpForce;
jumpTimeCounter -= Time.deltaTime;
} else
isJumpimg = false;
{
{
}
}
{
if (Input.GetKeyUp(KeyCode.Space))
{
isJumpimg = false;
}
}
}
}
【问题讨论】: