Using class variables in another script (c#)

Problem was fixed by myself.

admin please delete.

Please use the code tags so that it makes it easy to read and interpret the code.
http://forum.unity3d.com/threads/143875-Using-code-tags-properly

I don’t see why classname newclassname = new classname(); shouldn’t work?
You are referencing the class of the previous script with a new class (object) and thus you can access the variables of the first script by using “newclassname.thevariable”

I don’t know why it doesn’t either (hence the forum post) I’ve had this error pop up from time to time too.

“Object reference not set to an instance of an object” have seen posts sayings its to do with MonoBehaviour but the fixes they have used didn’t work for me.

You have to call the constructor… so if your Class is called PlanetClass you need to make a constructor for planetclass that takes inputs.

then you make a variable inside your script like this

private PlanetBuilder planetbuilder;

call the constructor in your Start then use your getters setters to alter or grab your variables, or call your constructor with the variable inputs to build it all at once. You can then pass this Class around to other scripts.

Hope that helps

Public class PlanetBuilder : MonoBehaviour {
private float population;
private float blackmatter;
private float xcord;
private float ycord;

public PlanetBuilder()
{
}

public PlanetBuilder(float pop, float matter, float x, float y)
{
population = pop;
blackmatter = matter;
xcord = x;
ycord = y;
}

//getters setters

}

Already tried that…just get this error