- Home /
GUI Texture Problem
Hello. I have a problem with a simple GUI button where I have 2 textures. One that is normal button, and the other where the button is hovered. Here is my script :
var normalTex : Texture2D;
var hoverTex : Texture2D;
function OnMouseEnter(){
guiTexture.texture = hoverTex;
}
function OnMouseExit(){
guiTexture.texture = normalTex;
}
So, I added a normalTex and in it put this script. Put my textures into normalTex, and hoverTex and when button clicked nothing happens. Problem with the script? Thanks.
So what works what doesn't? What mouse click are you talking about. Do you see the normal texture? when you do not hover over it?
Well I only see the normal texture. When I hover over the button and click it I only see the normal texture.
use a Debug.Log("you are"); in your On$$anonymous$$ouseOver to see if your mouse over is even getting registered. hoving
I put the Debug.Log("Clicked"); in the on$$anonymous$$ouseEnter function and it seems that it doesn't register it at all.
Answer by MC HALO · Jun 13, 2011 at 04:02 PM
I can see your problem :)
basically the script is all fine :) but the problem is on your functions all you need to do is change function onMouseEnter(){
to
function OnMouseEnter(){
you will notice that in your script you have written onMouseEnter. Now in unity if you are using its build in functions they always start with a capital so the on has to be On not on :) here is the correct code :
123 123 var normalTex : Texture2D; var hoverTex : Texture2D;
function OnMouseEnter(){
guiTexture.texture = hoverTex;
}
function OnMouseExit(){
guiTexture.texture = normalTex;
}123
123
other than that your code is great i hope this has helped you :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612104104im_/https://answers.unity.com/themes/thub/images/avi.jpg)