- Home /
Why Is OnMouse Not Working Correctly?
Sorry for the generic always asked question, but my OnMouse isn't working correctly. On all the tutorials I've seen, when the person hovers over their GUI Textures, their script allows their textures to light up indicating that they're over it. But when I do it, it worked for most of the GUI Textures, but not all. If I remember correctly there are about two that don't work. One won't let me hover/click it at all, and another won't let me click it unless I go to the bottom of the screen, then it shows up. So what could be the problem? Are the GUI Textues too close to each other, or something else? Here's my script so I don't look crazy:
public class Click : MonoBehaviour {
public Texture2D normalTex;
public Texture2D hoverTex;
void OnMouseEnter(){
guiTexture.texture = hoverTex;
}
void OnMouseExit(){
guiTexture.texture = normalTex;
}
void OnMouseDown(){
AudioManager.AudioInstance.PlaySound ("Sound");
Application.LoadLevel("Scene1");
}
}
It's the script for the one that actually let's me click it, the other button has the same script except a different scene loader. Here is how my GUI Textures are arranged:
This is the one that I have to go all the way to the end of the bottom part of the screen(wow that was a lot of "the"). So it let's me click it, but not right on it. The other GUI texture that doesn't let me click on it uses the same structure. So what can I do? By they way I use OnMouse because I'm developing my game for IOS Ipad/Ipod touch.
"By they way I use On$$anonymous$$ouse because I'm developing my game for IOS Ipad/Ipod touch." How does one hover over a button on a touch device...?
You don't. I'm simply using it because some have said that GUI Buttons are not very good with IOS. Can you confirm this? Although when you do click the texture, it still has the hover texture play. You just won't be able to see it for very long.
Answer by brycem24 · Aug 16, 2014 at 07:24 PM
Two things, I believe that for IOS you can use Input.GetTouch. void OnMouseEnter should be changed to OnMouseDown. void OnMouseExit should be changed to OnMouseUp. and finally void OnMouseDown should be changed to OnMouseDrag.
I'll try that, thanks for the suggestion. I'll come back and tell you if I got it working or not.
Alight so I tried it. All it did was stop the mouse from being able to change the texture when hovering over it, it did not change how the buttons are click. The only difference is that now I can't tell if I've hovered over it, which isn't a problem since this is IOS, but I can't click the buttons directly. In order to click the bottom button, I have to click the bottom part of the screen. In order to click the middle, I have to click the top button. Finally in order to click the top, I have to click right above it.
By the way, I didn't use Input.GetTouch, as I don't know how.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Get Selected Object In Editor 2 Answers
Is it possible to link character skill lists to a GUI, and if so, how? 3 Answers
Gameover function calling before game ends help 2 Answers
Scene Selection 1 Answer