- Home /
Can't focus on Textfield when webplayer is online
Hello Unity masters !
I am nearly done with my web project but only one thing still bother me.
When I ask the player to type his name for the scoreboard, a textfield shows up. I use the GUI.FocusControl to focus on the textfield to avoid the player to click in the textfield.
Here is the code :
function OnGUI ()
{
if (dispNameInput)
{
// Set the internal name of the textfield
GUI.SetNextControlName ("MyTextField");
// Make the actual text field.
curName = GUILayout.TextField (curName.ToUpper(),9);// Got ot put the string variable before to have the textfield editable (typable)
if (focusOnplayerName)
{
focusOnplayerName = false;
GUI.FocusControl ("MyTextField"); // focus on input player name
}
}
}
When I do a webplayer build and open the html file to test it, the focus is PERFECTLY done. But when I put the same files on my website and test it, the focus is NOT done. And above all, when the player type his name, sometimes, the typing get stuck.
You can try the game if you want to test :
(when you lose, the game ask for saving the score. choose "yes" to see the problem with player's name texfield)
Thanks for your help.
Answer by PaulUsul · Jan 21, 2014 at 02:09 PM
First of all what a really fun game!
I'm not quite sure this is correct, but I'm guessing it's because your web player application does not have focus. This does not affect that many things other than a few mouse issues and some OnGUI stuff and maybe your problem(GUI.FocusControl).
You can test it by adding the function OnApplicationFocus and logging on it and then re-testing again when you know your application has focus.
Thanks Usul!
First of all, thanks for having played my game. :)
You say that maybe my web player does not have focus. You are talking about the .unity3d file build? In that case, maybe I am missing an option for my application to accept focus?
Or maybe you are talking about the web browser?
I checked the OnApplicationFocus but I still don't get how this would help.
Well.. There isn't actually a bug right now in your game. It just only works when the .unity3d web player has focus. Try clicking the window before you lose, it works! Click outside the window and lose and it doesn't work.
The way I usually fix this kind of issue is by overlaying something when focus is lost, forcing the player to click the little unity web player window; like a play icon that disappears on OnApplicationFocus.
Ok, I understand the way I could manage this with your indications.
It's just too bad there is no option to keep focus on the textfield not matter what happens.
Thanks for your help, Usul !
By the way. Here in France, we got a youtuber named USUL who makes video about videogames topics. The show is called "3615 USUL".
Have a look here ;D http://www.youtube.com/watch?v=O-AgqS$$anonymous$$NyH4
Bye.
haha that's awesome, my dad was just a big sci-fi fan. It's from Frank Herberts - Dune.
It is a really annoying problem, but it does make sense. Unity can't give it focus, when it itself does not have it. Imagine if you could type in skype while typing in your browser, would be way weird.
$$anonymous$$aybe there is a hack where you force the browser to focus on the unity3d window through html. I don't recall, it's 2-3 years ago I had a problem similar and I no longer have the code, sry :(
Your answer