- Home /
How can i dynamically change texture
Hello Everyone,
Does someone know what is the syntax for UITexture? I have this code below but i do get this error upon hitting start? "NullReferenceException: Object reference not set to an instance of an object ChangeTextureImageBox.Start () "
UITexture textureComponent = GetComponent<UITexture>();
textureComponent.mainTexture = Resource.Load("texturename") as Texture;
textureComponent.MakePixelPerfect();
What i want to do is dynamically change the texture of object through condition. Any advice and tips would be much appreciated, BTW that is a class from UIWidget from NGUI. http://tasharen.com/ngui/docs/class_u_i_texture.html
Are you sure UITexture
component is attached to this game object? And is the texture you load located in Assets/Resources folder?
Answer by el-santia93 · Nov 28, 2013 at 04:33 PM
try this
var normalTexture : Texture2D;
var rollOverTexture : Texture2D;
function OnMouseDown(){
//or you could just have your condition instead
guiTexture.texture=rollOverTexture;
yield new WaitForSeconds(4);//or a reverse condition
guiTexture.texture=normalTexture;
}
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Get a UV texture of a models surface 2 Answers
Adding Fog 3 Answers
how to create illumination mask texture loading script? (self-illuminated diffuse) 1 Answer
change bar position 1 Answer