Invalid Type Issue - Advise Request

I am using Unity 3.52. My Scene contains a player object called Rover. The inspector shows that Rover has a Transform, Cube, Mesh Renderer, Character Controller, Rover Camera Follow (script = RoverCameraFollow.js), Rover Stats (Script = RoverStats.cs) and an item I don’t recall adding called Mono Behaviour (Script = Missing Script) that has identical properties to Rover Stats.

Both the RoverStats.cs and RoverCameraFollow.js are in the Project under Standard Assets/Scripts folder. However, the compiler gives me an error on this line in RoverCameraFollow.js

private var roverStats: RoverStats.cs;

BCE0018: The name ‘RoverStats.cs’ does not denote a valid type.

Changing it to the following didnt help either:

private var roverStats: RoverStats;

Did I define the RoverStats class incorrectly with:

public class RoverStats : MonoBehaviour { ...

(I think this means that RoverStats is derived from MonoBehaviour). Could be why I have this MonoBehaviour item in the inspector. Changing the line to be :

private var roverStats: Monobehaviour;

Allows the compile to work but with the message :

The reference script on this Behaviour is missing !

I seems to have something not quite correct. Please advise.

This

private var roverStats: RoverStats;

is the good way to declare your var. Note that a private var doesn’t show in the inspector though. The missing script error is different. When you attach a script to a gameobject, the first line under the foldout is the reference to the script. You can see the little dot on the right, which open a window with all the script in your assets folder when you click it. Find the correct script and assign it.

That’s the problem when you mix C# with UnityScript (Unity’s Javascript). Different languages (C#, UnityScript, boo) can’t see each other, unless one of them is placed in a different compiling group. All scripts, no matter what language, can see all scripts from a previous compiling group, but not reverse.

See script compilation order.

Btw, it has to be:

private var roverStats: RoverStats;

The file extansion isn’t part of classnames.

The missing MonoBehaviour is probably your RoverStats script that you have attached previously, but then you moved or renamed the script outside of Unity, so the script linkage has been lost. Unity doesn’t know this is still the same script since it’s a different file (location / name). If you want to rename or move any asset, do it inside of Unity. Never do it in the Explorer / Finder.

You can delete the MonoBehaviour since it’s just a dead link. Instead of adding another new instance of your RoverStats script, you could have dragged the RoverStats script onto the Missing MonoBehaviour’s “script” variable to relink the script. This way you don’t loose your old settings which are stored (serialized) in the instance.

Thank you for the replies.

The only remaining issue I have is that the JS script compile does not yet see the public class RoverStats defined in the CS script due to script compilation order. Unfortunately, after reading the ‘script compilation order’ link a few times I cannot figure out how to resolve the issue. Therefore, I have decided to eliminate the need for the need for the JS to see the CS Class by moving the logic that moves the Rover (player) from the update method of the RoverCameraFollow into the Update method of the RoverStats.

At some point, I think that I should convert the JS code to CS and make all the scripting into one language. I am reluctant to do so now because I’m afraid that I will break the project when I incorrectly try to swap in the CS version of the JS script.