- Home /
Loading GUI in middle of mouse and make it work radial
I'm doing a top down game and the idea is that when a player clicks and holds on a object it will present a radial GUI around where the mouse pointer is and the player can choose the options from it (point and click style).
THe way for choosing the options is similar to Maya radial menu where you click and hold, then drag the mouse to the option you want and lift it.
I managed to get the GUI to show where the mouse is when clicking on the object but its always aligned to the top left corner.
Also I have no idea how to disable the mouse from controlling the camera and getting it to control the new UI (and stop the UI from following the mouse for a few secs so you can choose the option).
Here is an example of what I mean as a radial menu: http://www.youtube.com/watch?v=edp_ZCzBG08&feature=player_detailpage#t=237s
Just an update. I've been trying all day to do this and managed to learn quit a bit more about Unity. Using the UnityGUI I'm able to have the UI show where the mouse clicks and stay there when the character moves. I've also managed to create actions for the buttons.
The only issue now is that I can't find a On$$anonymous$$ouseUp control for the GUI. The idea is that the player presses and holds the L$$anonymous$$B to see the radial menu and then drags the mouse (while still holding) over the button he wants to activate.
The problem I have is that the current UI doesn't detect just releasing the mouse from hold as a button press...
Could you use input.Get$$anonymous$$ouseButtonUp(0) on an UpDate() and do what you need from there?
@lodendsg: You shouldn't mix the Input class with GUI stuff ;) OnGUI has it's own event management.
It's fine to use Input.Get$$anonymous$$ouseButtonDown in Update to set a boolean which will display the GUI, but interactions with GUI elements should be handled in OnGUI itself.
Hello! I have installed a Pie$$anonymous$$enu component and customized the style of it. But I have problem with the action of the buttons. There are 3 buttons by the menu. When I click one of the buttons the project runs this script:
using UnityEngine;
using System.Collections;
public class $$anonymous$$enuItemActions_3 : $$anonymous$$onoBehaviour {
void OnSelect(string command) {
Debug.Log("A Left $$anonymous$$enu Command Received: " + command);
}
}
The piemenu object has a setting for commands. The string data is One Two and Three as default. How can I change these datas to open each button a GUI texture separately?
Answer by Bunny83 · Sep 10, 2012 at 01:24 PM
When someone talks about a radial menu i always think of the old second life pie menu or L4D voice menu. I never used Maya ( since i'm a programmer :) ), but the menu seems to look way differently than i would imagine a radial menu. Well, it doesn't actually matter :D but a screenshot of your menu would be a better reference since we can also see what's the problem.
Ok, now to your menu. The UnityGUI elements are ment as usual gui controls. So a click on a button is only counted when you click down and release on the same button. That's the normal GUI behaviour in almost all GUIs. In your case you have to test the releases yourself. You could write your own "GUI control"-function (like Button()) but only react to mouse up and ignores the mouse down event.
// C#
bool ReleaseArea(Rect aRect, GUIContent aContent, GUIStyle aStyle)
{
Event e = Event.current;
bool isOver = aRect.Contains(e.mousePosition);
if (e.type == EventType.Repaint)
aStyle.Draw(aRect,aContent, isOver, true, true, false);
else if (isOver && e.type == EventType.MouseUp)
return true;
return false;
}
void OnGUI()
{
if (ReleaseArea(new Rect(10,10,200,50), new GUIContent("Button1"), "Button"))
{
// mouse was released on this area
}
}
Thanks for the help! Would it be possible to show the answer in javascript too?
just change the order of things and you have js (don't forget to add var in front of declarations like i did :)
Event e = Event.current; // C#
var e : Event = Event.current; // js
bool ReleaseArea(Rect aRect, GUIContent aContent, GUIStyle aStyle) // C#
function ReleaseArea(var aRect : Rect , var aContent : GUIContent , var aStyle : GUIStyle ) : bool // js
http://wiki.unity3d.com/index.php/Csharp_Differences_from_JS
Your answer
Follow this Question
Related Questions
FPC Mouselook Axis problem on pause GUI 1 Answer
menu issue and mouse click 0 Answers
Gui Menu - Help Please. 2 Answers
changing from mouse click to keys 0 Answers
GUI not work after building 1 Answer