Home > other >  I'm getting an error when I try to access `EnginePower` from Unity StandardAssets script
I'm getting an error when I try to access `EnginePower` from Unity StandardAssets script

Time:07-12

Im trying to access the variable "EnginePower" from the script AeroplaneController see code below

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;  
 }
}

As you can see, Im setting FSpeed to be equal to EnginePower multiplied by 5.714285714285714 But im getting the error The type or namespace name 'AeroplaneController' could not be found (are you missing a using directive or an assembly reference?)

EnginePower IS public, AeroplaneController is a Unity StandardAssets script.

CodePudding user response:

AeroplaneController might be in another namespace

Try using XXXnamespace.AeroplaneController, or just add a using at the beginning of the code

CodePudding user response:

Adding to what @LafiteCandy said:

Change Aircraft.GetComponent<AeroplaneController>() to Aircraft.GetComponent<UnityStandardAssets.Vehicles.Aeroplane.AeroplaneController>()

  • Related