Texture2d Change Texture by MouseClick


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

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)