Change Textures when button is pressed in Unity 5.3!!!
Hello people,
I am really new to programming (C#) and have the following problem:
I just want to change a texture. This texture is part of a material which is on a lot of game objects. So, I want to swap the existing texture on all the objects to my new texture when I press a button.
In the past there were solutions like:
public Texture myTexture;
void OnGUI() { if( GUI.Button( new Rect(0.0.100.40), "change texture" ) { gameObject.renderer.material.mainTexture = myTexture; } }
But this way seems not to work any longer. Also the GUI System has changed and I am not used to how to connect my button when it's pressed to my function. Could anybody help me please? I'm going mad with this stuff!!! Please post the whole code from the first to the last line if possible because sometimes I even don't know how to begin or if I need things like: using UnityEngine.UI;
Thank you so much!!!
BR
Aljoscha