[英]Unity/C#: I can not work out why this variable doesn't exist in the current context
這是我的全部代碼,因為這個問題讓我完全困惑:
public class Controller : MonoBehaviour
{
public float stalls;
public float IntegerYVelocity;
public float TotalJumpForce;
public float TotalDropForce;
public float jumps;
public float speed;
public float jumpForce;
public float dropforce;
bool isGrounded = false;
public Transform isGroundedChecker;
public float checkGroundRadius;
public LayerMask groundLayer;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
TotalJumpForce = rb.velocity.y + jumpforce;
TotalDropForce = rb.velocity.y + dropforce;
CheckIfGrounded();
Move();
Jump();
Drop();
Stall();
}
void Move()
{
float x = Input.GetAxisRaw("Horizontal");
float moveBy = x * speed;
rb.velocity = new Vector2(moveBy, rb.velocity.y);
}
void Jump()
{
if (Input.GetKeyDown("w"))
{
if (jumps > 0)
rb.velocity = new Vector2(rb.velocity.x, TotalJumpForce);
jumps = jumps - 1;
}
}
void Drop()
{
if (Input.GetKeyDown("s"))
{
rb.velocity = new Vector2(rb.velocity.x, TotalDropForce);
}
}
void CheckIfGrounded()
{
Collider2D collider = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer);
if (collider != null)
{
isGrounded = true;
jumps = 2;
}
else
{
isGrounded = false;
}
}
void Stall()
{
if (Input.GetKeyDown("q"))
{
if (stalls > 0)
rb.velocity = new Vector2(rb.velocity.x, 0);
stalls = stalls - 1;
}
}
}
但后來我得到這個編譯器錯誤:
Assets\Controller.cs(29,42): error CS0103: The name 'jumpforce' does not exist in the current context
這讓我很困惑,因為一切都很好,直到我添加了攤位無效。
您忘記將第 29 行的“jumpForce”中的“F”大寫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.