Open UI Panel on Mouse Position
Good Evening
Can someone please give me a Tip on how to do that? I tried Input.mousePosition but the Panel follows the mouse, I want it to stay at its Position. I just cant get it to work.
Answer by Dibbie · Nov 07, 2015 at 01:38 AM
You could try adding a EventTrigger to your object, and using the Mouse Over/Pointer Enter attribute, then attach a script to that attribute that will show your panel.
Answer by taifun4744 · Nov 07, 2015 at 10:26 AM
Good morning
Thank you Dibbie. Hmm but that is not quite what I want. I want it to Show always on Mouse Position and stay. Like a Rightclick Menu. It Shows up when you Rightclick on the Canvas and stays.
Answer by OctoMan · Nov 07, 2015 at 10:57 AM
So you just want to show a panel where it is when you mouse over a button?
You can use A Raycast or OnMouseOver().
Once you are over that button, just set the panel to active
public GameObject PanelToShow;
void OnMouseOver()
{
PanelToShow.SetActive(true);
}
else
{
PanelToShow.SetActive(false);
}
[1]: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html
Good $$anonymous$$orning
No, Im Sorry. I just cant get you to Understand. I have a GameObject Panel, and I have shortcut $$anonymous$$ey for that Panel. If i press that shortcut, the Panel Shows up. Now I want it to Show where the mouse is. If I use this script below, i get it to Show on mouse Position but it follows the mouse. And I dont want that.
public GameObject Panel;
private bool ShowPanel;
void Start(){
Panel.SetActive (false);
}
void Update(){
if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.A)){
ShowPanel =!ShowPanel;
Panel.SetActive(ShowPanel);
}
Panel.transform.position = Input.mousePosition;
}
Just take
Panel.transform.position = Input.mousePosition;
out of Update anyhow. Otherwise it will stay at mouseposition.
Edit: Corrected my answer. Sorry
void Update(){
if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.A)){
ShowPanel =!ShowPanel;
Panel.SetActive(ShowPanel);
showpanel = true;
}
if (showpanel && ShowPanel)
{
Panel.transform.position = Input.mousePosition;
showpanel = false;
}
}
$$anonymous$$aybe this works.
Hi
Thank you Octo$$anonymous$$an. I got it to work. Herzlichen Dank.
public GameObject Panel;
private bool ShowPanel;
void Start(){
Panel.SetActive (false);
}
void Update(){
if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.A)){
ShowPanel =!ShowPanel;
Panel.SetActive(ShowPanel);
if (Panel && Panel) {
Panel.transform.position = Input.mousePosition;
}
}
}
}
Answer by noumankhan00 · Oct 25, 2018 at 08:10 AM
hy,WITH which object i attach this script camera or panel ?
Your answer
Follow this Question
Related Questions
[SOLVED] Image is not visible in Panel (in game view) 0 Answers
How do I use anchors in UI? 0 Answers
Panel with Values From Array 1 Answer
Dynamic width panel 1 Answer
How do I detect if my mouse is over UI? 0 Answers