I am having a very weird issue which I have not encountered with Unity before. I have a menu screen with several GUITextures and GUITexts that get clicked. Sometimes when I run the game in the editor they work, sometimes they don’t until I quit and restart Unity. What’s more, sometimes the builds I make work (clicking on the GUITexture objects has a result) and sometimes they don’t. There seems to be no clear rhyme or reason to this - the only pattern I have noticed is that if I build with a scene other than the menu scene open in the editor, the build tends not to work.
It appears to only be the menu scene that has a problem - and that is the only scene where GUI objects get clicked.
Any ideas where this problem is coming from?
Sounds like your code assumes a given order in the execution of the start or awake functions to set itself up correctly, which would be a problem as there is no such order.
I’ve cut the Start and OnMouseDown functions down to the following code:
function Start(){
Screen.lockCursor = false;
}
function OnMouseDown () {
if (index == 1){
print ("One");
}
}
Again, sometimes it works, sometimes it doesn’t, despite the steps taken when using it being exactly the same.
It seems like that would eliminate the order issue possibility, right?
OK. I’ve done more testing. I added some code to check for mouseDown on 3D objects with box colliders and they work fine even when the GUITextures and GUITexts don’t.
So the problem is clearly with the GUI objects not recognizing clicks - is this a known issue? Any ideas how to combat this?
GUITexture and GUIText are no gui objects. They are “always visible rendering components”
GUI objects are always GUI.xxxx like GUI.Button etc
As for your code: thats worthless as that will not replicate anything. You use index == 1 with no existing index so it can be anything including a initialization mess and whatever.
i had the same problem too with my gui … the same button work on the unity and dosen’t work when i build it …!!!
i have mad from this problem and then i change the gui button to a planes with onMouseOver and onMousedown events on it and then everything work good … donno why this problem happened with the gui … if any from unity team reply us??
dreamora, thanks for taking the time to explain some of this to me. I am not sure how the code is worthless or what a better way of demonstrating what I am doing would be. The index is a variable that I set in the editor. I use that one script for several objects. One of the objects has index set to 1, another to 2 and so on. For the purpose of trying to test if there was some issue with the code and the order that things are being done, I simplified the code so that it was only being used by one object to test on just that one object.
But the issue remains that with my game the “always visible rendering components” sometimes respond to mouse click and sometimes don’t while 3D mesh objects with box colliders always respond and I would like to be able to fix that and it doesn’t seem to be a problem with the code I am using.
Well, due to time pressures, I have given up on this one and decided to use a system similar to what Hanankk wrote about. It makes layout more complex and meant recoding and re-setting up the menu level but at least it is consistent now.