- Home /
Texture2d Change Texture by MouseClick
Hey,
I want to create my own buttons, but it doesn't work.
I have 2 pictures which are nearly the same, exept the "darkness".
So I made a GUITexture and I dragged the first one(the lighter one) on it, that works
Then I added a JsScript.
Here's my question... How can I change the Material of the GUITexture by script when the GUITexture gets clicked
Something like:
function OnMouseDown () { //change the Material of the GUITexture to the darker image //load the next level/load the next scene }
function OnMouseExit () { // change it back to the brighter one/the normal one, I added first }
If GUITexture are the wrong choice for that, please give me another soution
Answer by longisle · Nov 19, 2010 at 08:52 PM
You have mixed some things a bit:
these you can use to give even more effects, for example highlight the button.
function OnMouseEnter () // when you hover your mouse over the button.
function OnMouseExit () // when your mouse leaves your button area.
This is what you want to use:
function OnMouseDown () // when you click down your mouse button.
(this is where you want to have your texture change)
function OnMouseUp () // when you lift up your mouse button.
(this is where you want to load new scene, if earlyer, then your effect loses its point)
Your answer

Follow this Question
Related Questions
How to change a guiTexture color when a float is a certain number? 1 Answer
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Changing texture for pause button 1 Answer
Change texture of GUItexture from script 4 Answers
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer