I’m trying to set a Texture in a script modified to be a database. How do I set the Static variable? I know textures can be set in the inspector by looking at the script itself but statics don’t come up in either the transform or the script. (as far as I am aware) I’m just trying to set the static to be referenced elsewhere.
Do this:
Declare 2 vars;
- var textur : Texture;
- public static var textur2 : Texture;
In Start() function
insert this :
textur2=textur;
Now the texture you assinged via inspector in var textur is dublicated in textur2 which is a static var ready to pass it to any other script.
Hope i was helpful. ![]()
If I have understood correctly you want to set your static Texture through the insepctor. That is not possible because static variables are not shown in the inspector. Your choices are:
- Modify the inspector so you can see static variables (Unity - Scripting API: Editor).
- Load the texture withing the script (Unity - Scripting API: Resources.Load)
- Use a singleton.
If you follow last option you could make a class like this:
public class TextureThroughInspector : MonoBehaviour{
public Texture textureNonStatic;
public static Texture texture;
void Start(){
texture = textureNonStatic;
}
}
However that is a bad practice because the non-static texture should be made private, and also there wouldn´t be any need to make it a child of MonoBehaviour, I only did it so you can set it through the inspector.
I think the best you could do is implementing a good singleton solution while loading the texture from a local file (no need of using inspector here).