I want my button to change appearance when a finger is on it. Is this not doable via GUIStyle in the way it is with a mouse click? I don’t see why it shouldn’t be; I tried active and hover - is this available via one of the other variables?
Edit (repeated below): As it turns out, this is actually just a problem in the Editor. The active states work fine upon build. UT has been made aware. 8)
there is no “mouseover” or hovering as any movement triggers a drag. if you want to missuse “drag” as “mouse over” you will likely have to code that yourself
In that case I’m sorry because your description “I want my button to change appearance when a finger is on it” describes hover unless you wanted to express “if you press a button” with that
True. I didn’t think about the “mousing around” with a finger down, as far as buttons are concerned. But I still don’t know if there’s a built-in state for this. It ought to be the “active” state, but it’s not.
Description wise it would be active, which changes the style while you press the button.
Perhaps it was just forgotten / ignored as you normally do not have such massive buttons that you see the style at all, because you need to have an animation or something to see it after take away the finger but unity is immediate, so you wouldn’t see it.
The alternatives are focused and hover.
Unity does not have a style for “active buttons” as they don’t exist in immediate guis. Buttons are recreated every OnGUI so its up to you to give it a different style altogether to seperate inactive active gadgets. Just in case this is what you actually wanted to reach
GUIStyles have built-in variables for background images, for different button states. I just want to be able to use one for a “finger click”. I think that should be “active” - I see putting a finger down on a button as a clear parallel to a mouse click.
I would just like a clear answer from someone who knows for certain - , in Unity iPhone, is there any variable built into a GUIStyle that is a parallel to “active”, for a mouse click?
I did some testing with a web player, and realized that the hover state should indeed be implemented too. As it is, if you click outside of any control, and then mouse onto a control with a hover state, while still clicking, the hover state will then be visible. That should carry over to the iPods: if you touch the screen outside of a control, and then slide your finger over another, the hover state should be triggered.
Thats not what hover means.
Hover on the iphone is not possible as there is no mouse over. There is only mouse drag or mouse down because the mouse only exists while you have clicked the screen.
Hover is when the mouse is moved over a gadget without having a button pressed, in case above does not make much sense.
For that reason it can not carry over to the iPhone, only “dragOnto” would be possible. But as Unity GUI is immediate, this state does not exist as dragging is pure code.
Also, this state can easily be implemented through your scripts, just use a different style when drawing the button.
It might just be that the implementation does not make a difference between mouse down and not down when the mouse moves in.
That would explain its behavior and also explain why it does not work on the iphone. Because mousemove (mouse movement independent on pressed buttons) does not exist on the iphone
But yeah some more usefull GUI capabilities would be nice thought GUIStyle is something you don’t use on the iphone … you even avoid the GUI unless you need it as it quite a bit slower than self implemented GUITexture based own implementations.
Background. My first Unity3d Game. I read how OnGUI was not ideal for mobile games. Much like Dreamora said. So what I did for that game was only used OnGUI to do a GUI.DrawTexture for my button images. I had a Rect made which I would do a Rect.Contains(myTouch). If it did, the only way I could notify the player that the button was pressed was to slightly enlarge the button. I would have loved to have a different image become active but couldnt find a solution to my problem.
Fast forward to my latest prototype, I have a test game scene that I was messing around with. All I want to do is create a button that will change to another image when it is touched.
That “GUIStyle style” variable is set up in the Unity Editor / Inspector to have a different image for Normal and Active states:
using UnityEngine;
using System.Collections;
public class buttons : MonoBehaviour {
public Texture aTexture;
public GUIStyle style;
void OnGUI() {
if (GUI.Button(new Rect(10, 10, 50, 50),“CLICK ME”, style))
Debug.Log(“Clicked the button with an image”);
}
}
This works great when I run the game within Unity. Haven’t tried in my project yet and haven’t built to my iPhone yet to try it.
If this is not ideal, then can someone just provide me with a tried and true way to do the following:
A.) Display a button image on the screen somewhere.
B.) This button will change to a “CLICKED” image when touched.
C.) This code will work on iOS, Android and hopefully Unity Editor, Windows and OSX as well.
I tried some NGUI Asset Store stuff but it was very convoluted and I had little to no luck with it in the past.