GUItexture change on mouseenter

Hi all, i have written a script for when i hover over an object such as a cube, it changes the guitexture to a hand, then when i take my mouse off the object it returns back to its original state. i attached it to a GUItexture and it didnt work, and i did it to the cube and it didnt work, heres the script. Any editing or advice is appreciated

var hoverTexture : Texture; 

function OnMouseEnter() {

guiTexture.texture = hoverTexture;

}

Three problems:

  1. You need to define a function for switching the texture back to normal afterwards.
  2. You need to declare a variable for your GUI texture
  3. A 2D texture in Unity is declared with “Texture2D”, not “Texture”

Try this, it should work:

var targetGui : GUITexture;
var hoverTex : Texture2D;
var normalTex : Texture2D;

function OnMouseEnter() {
targetGui.Texture = hoverTex;
}

function OnMouseExit() {
targetGui.Texture = normalTex;
}

Good luck! :slight_smile:

I wish if i can understand Java script
2 years and still i don’t know how to code in unity :frowning:

Old question, I’ll add in anyway, just in case.

it’s actually tagetGUI.texture = normalTex;

using the capitol in “texture” won’t work.