Varible, Assigment!

Greetings,

I have been working whit Unity3D for awhile, and I have been able to accomplish pretty much everything that I have wanted to make in my game!

But…

There is one thing that I have never understood, and even though I have been looking everywhere for answers whitout any luck, I have never bothered to ask before now becuase this prevents me suddenly from doing everything I want…

I am pretty sure it’s easy, but I just dont understand the way it works so if anyone deside to help, please teach me why it is working as it is, since it obviosly dont make sence to me…

When I script, and want to define varibles like “GameObject, Texture, Material, Texture2D” etc, they need to be static to be able to be used later on in the code! This, make sence, ofc!

BUT… To be able to assign anything to these varibles, in the “Inspector” so that I actualy know what “GameObject, or Material” I am going to use in the code, the varible needs to be non-static!

I do know that I can look for the “GameObject” by tag, or even name, and the same whit “Materials” and what not, but I want to assign them in the “Inspector”, just the same as you can when you do this with “Javascript”… (Obviosly this is scripts made in C#)!

I need to use C#, and I dont want to manualy script the assignment!

Please, help me!

Best Regards,
Marius Alexander Winsjansen

actually if you wrote a script, it will not take any effect while it hasn’t at least one instance. script in unity is a component (MonoBehaviour child), and like any other caomponent, can be attached to any GameObject. Once it attached, it has an instance here and any variables/assets can be assigned to this instance. you can have so much instances as you wish, and all with it’s own varialbes assigned.

static variables also can be used as well, but not for storing assets. assets “for future use” can be stored in Resources folder (special folder name that always goes to builds)

When I script, and want to define varibles like “GameObject, Texture, Material, Texture2D” etc, they need to be static to be able to be used later on in the code! This, make sence, ofc!

This is completely untrue. Variables should never be static unless you specifically want only one instance of them in that class, in which case it’s logical that they can’t be assigned in the inspector. (Since everything in the inspector is an instance, which is diametrically opposed to static.)