【发布时间】:2022-10-17 23:06:53
【问题描述】:
在统一使用 C# 时,我制作了这个跳转脚本来控制玩家。当我运行下面的代码时,我得到如下所示的错误
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
public float JumpForce;
[SerializeField]
bool isGrounded = false;
Rigidbody2D RB;
private void Awake()
{
RB = GetComponent<Rigidbody2D();
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
if(isGrounded == true)
{
RB.AddForce(Vector2.up*JumpForce);
isGrounded = false;
}
}
}
O refrences
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("ground"))
{
if(isGrounded == false)
{
isGrounded = true;
}
}
}
}
出于某种原因,我在 vs 代码中没有收到任何错误,但是当我进入游戏时,它会显示下图所说的内容。如果你有答案,那真的很有帮助,谢谢。
【问题讨论】:
-
我无法解释不显示错误的代码,但您在
GetComponent<Rigidbody2D();中缺少>。 -
前两个不是编译器错误,而是运行时警告..顺便说一句:绝对没有必要/使用尝试对我们隐藏时间戳^^
标签: c# unity3d visual-studio-code compiler-errors