簡體   English   中英

當我嘗試從 Unity StandardAssets 腳本訪問“EnginePower”時出現錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM