- Home /
how do I set a static Texture?
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.
Answer by an-ch · Nov 15, 2013 at 10:42 AM
Do this: Declare 2 vars; 1) var textur : Texture; 2) 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. :D
Answer by MrVerdoux · Nov 15, 2013 at 10:49 AM
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 (http://docs.unity3d.com/Documentation/ScriptReference/Editor.html).
Load the texture withing the script (http://docs.unity3d.com/Documentation/ScriptReference/Resources.Load.html)
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).
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Texture Alpha cutoff + Photoshop 0 Answers
Video Texture - Alpha 3 Answers
how to change the maintexture from another scene? 1 Answer
need help in texturing a city.. 2 Answers