我正在學習統一 3d 游戲開發,我正在按照教程撰寫此代碼,以便球在其 X 軸上施加力,但統一表示必須在進入 Playmode 之前解決所有編譯錯誤:
代碼:
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 啟動和 void 更新功能的錯誤。請幫忙
uj5u.com熱心網友回復:
如果沒有錯誤資訊,這有點難以除錯,但我確實看到您的代碼有兩個錯誤。
GetComponent<RigidBody>首先,當類的實際名稱為參考時,您呼叫的 Update 函式有錯字,Rigidbody請參閱 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);
}
}
uj5u.com熱心網友回復:
嘗試在 void 更新中定義 getcomponet 變數,然后先用變數創建一個新行,然后是速度事物或/并使用 = insted of =。
uj5u.com熱心網友回復:
也不要先使用命令
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/483185.html
上一篇:訪問陣列元素中的前一個元素
