- Home /
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;
}
Answer by THEpancakes · Sep 01, 2012 at 05:55 PM
Three problems:
You need to define a function for switching the texture back to normal afterwards.
You need to declare a variable for your GUI texture
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! :)
@THEpancakes, ive used your script and applied it to my guitexture but it still isnt working, ive put the normal gui in there, the hover gui, but i dont understand the target gui. Any advice?
Unity indicates in the debug bar that the issue is related with the texture member of the GUITexture object. This is the Unity console message (also is commented by Bloodyem):
'Texture' is not a member of 'UnityEngine.GUITexture'. Did you mean 'texture'?
Answer by sami · Sep 01, 2012 at 09:50 PM
I wish if i can understand Java script 2 years and still i don't know how to code in unity :(
Answer by Bloodyem · Sep 05, 2013 at 10:09 PM
Old question, I'll add in anyway, just in case.
it's actually tagetGUI.texture = normalTex;
using the capitol in "texture" won't work.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
In Game Credits? 1 Answer
Texture for cross hair is is messed up 1 Answer