[英]I'm getting an error when I try to access `EnginePower` from Unity StandardAssets script
我試圖從腳本AeroplaneController
訪問變量“EnginePower”,請參見下面的代碼
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Speed : MonoBehaviour
{
public GameObject Aircraft;
public Text SpeedText;
public float FSpeed;
// Update is called once per frame
void Update()
{
FSpeed = Aircraft.GetComponent<AeroplaneController>().EnginePower * 5.714285714285714;
}
}
如您所見,我將FSpeed
設置為等於EnginePower
乘以5.714285714285714
但我收到錯誤找不到The type or namespace name 'AeroplaneController' could not be found (are you missing a using directive or an assembly reference?)
EnginePower
是公開的,AeroplaneController 是Unity StandardAssets
腳本。
AeroplaneController
可能在另一個命名空間中
嘗試使用XXXnamespace.AeroplaneController
,或者只是在代碼的開頭添加一個 using
添加到@LafiteCandy 所說的內容:
將Aircraft.GetComponent<AeroplaneController>()
更改為Aircraft.GetComponent<UnityStandardAssets.Vehicles.Aeroplane.AeroplaneController>()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.