Hi,
I want to create an in-game right click menu. I want it to look like Windows right click menu. Also the buttons in the menu must be dynamically created since the menu will change with respect to clicked object. I tried using panels and instantiating button prefabs under it but I couldn’t place it in the desired position (top left of the menu must be on the mouse position). Any suggestions or tutorials?
There are many ways you could do this really, but basically you could just get the position of the mouse with something like; Input.mousePosition. Then use that position to well, position whatever you want the menu to be made out of.
I suggest you could try creating the menu dynamically with for example Ongui(); You should look into those (especially because they are very easily manipulated by script and therefore viable in loads of situations).
Not actual working code just demonstrating what I mean, e.g.
var mousepos = Input.mousePosition;
GUI.Button(new Rect(mousepos.x (+25*), mousepos.y (-15*), 50, 30), “Click”) ;
//*Note, I am not sure if the x and y coordinates are the center of the box, or the top left corner, but if they are you should add and substract 25px and 15px from the mousepose respectively, which is simply half the width and length of the box. If that is not the case then don’t do that.
this will create a button that is 50px by 30px with the text Click in it. The corners located at the position of the mouse. I could go into more detail how all that works, but really, you can figure that out yourself, good luck! 