Unity给出编译错误没有任何错误
Unity giving compile error without any error
我正在学习 unity 3d 游戏开发,我正在按照教程编写这段代码,让球在其 X 轴上施加力,但 unity 表示在进入 Playmode 之前必须解决所有编译错误:
code:
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddConstantForce : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetComponent<RigidBody>().velocity = new Vector3(2,0,0);
}
}
我有更新统一版本。尝试了各种新的示例场景,在弹出此错误后,它也给出了默认空空启动和无效更新功能的错误。
请帮忙
尝试在 void update 中定义 getcomponet 变量,然后先用变量创建一个新行,然后是 velocity or/and 使用 += insted of =.
没有错误信息,这有点难以调试,但我确实看到您的代码有两个错误。
首先,当 class 的实际名称是 Rigidbody
时,您调用 GetComponent<RigidBody>
的 Update 函数有错字,请参阅 Unity 的文档以供参考 https://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html
Vector3
之间也存在不明确的引用,因为 Systems.Numerics
和 UnityEngine
都定义了该类型。你想坚持 UnityEngine
定义。所以只删除第一行。
所以最后这段代码应该可以正常工作,没有编译错误
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddConstantForce : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetComponent<Rigidbody>().velocity = new Vector3(2,0,0);
}
}
我正在学习 unity 3d 游戏开发,我正在按照教程编写这段代码,让球在其 X 轴上施加力,但 unity 表示在进入 Playmode 之前必须解决所有编译错误:
code:
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddConstantForce : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetComponent<RigidBody>().velocity = new Vector3(2,0,0);
}
}
我有更新统一版本。尝试了各种新的示例场景,在弹出此错误后,它也给出了默认空空启动和无效更新功能的错误。 请帮忙
尝试在 void update 中定义 getcomponet 变量,然后先用变量创建一个新行,然后是 velocity or/and 使用 += insted of =.
没有错误信息,这有点难以调试,但我确实看到您的代码有两个错误。
首先,当 class 的实际名称是 Rigidbody
时,您调用 GetComponent<RigidBody>
的 Update 函数有错字,请参阅 Unity 的文档以供参考 https://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html
Vector3
之间也存在不明确的引用,因为 Systems.Numerics
和 UnityEngine
都定义了该类型。你想坚持 UnityEngine
定义。所以只删除第一行。
所以最后这段代码应该可以正常工作,没有编译错误
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddConstantForce : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetComponent<Rigidbody>().velocity = new Vector3(2,0,0);
}
}