- Home /
Get texture from gui to gameobject
Hello I have some problem with GUI. It is possible to change texture of selected game object from GUILable or from any GUIButton . I am using with OnMouseDown function for this but this function is not usable for GUI content so anybody know that how i can. I used guiTexture.texture=GameObjectName;
Thanks.
Answer by hotshot03 · Jun 14, 2013 at 11:16 AM
Texture btn_texture; // Texture used in the label or button or whatever
void OnMouseDown() { renderer.material.mainTexture=btn_texture; }
hi I have GameObject selectedObj; variable and i want to change this selected gameobject texture.
then, its selectedObj.renderer.material.mainTexture=btn_texture;
dude this is not possible because i want to pick texture from gui lable and apply on any gameobject so On$$anonymous$$ouseDown is not working with any GUI content.
Texture textureToDisplay;
void OnGUI () { GUI.Label (new Rect (10, 40, textureToDisplay.width, textureToDisplay.height), textureToDisplay); }
void On$$anonymous$$ouseDown() { selectedObj renderer.material.mainTexture=textureToDisplay; }