C# to Unityscript. Can't work out line of code.

Hi all,

I have this line off code in C# i am trying to understand and convert to Unityscript.

private JigsawMain main = null;

if i leave it as is in my .js file i get an Unexpected token: JigsawMain. error

if i convert it to.

private var JigsawMain : main = null;

I get the error. The name ‘main’ does not denote a valid type (‘not found’).
And if i change the word main to anything else i still get the same error.

the word main is used in the code many times.

if (main == null)
{

}
main = go.GetComponent("JigsawMain");

Also JigsawMain apart from being a empty object in the scene, is also the name of one the scripts in the project and the name of the public class in that script.

I really have no idea how to solve this.

Any help would be greatly appreciated. :slight_smile:

Thanks.

Chobi.

i think it should be :
private var main : JigsawMain = null;

Yep that works. :slight_smile:

That’s the first time i have ever seen a variable in unityscript like that.

Thanks for the help and the fast reply. :slight_smile:

All the variables in UnityScript look like that. In C#, you do this:

modifier type variablename;
private int myInt;

In UnityScript you do this:

modifier variablename : type;
private myInt : int;