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