繁体   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