- Home /
Object menu must be at the center of the object
I am creating a game with isometric camera. When i click on a object, i must open a menu localized at the center of the object, or at the center of the location where i click For example, now if i click on the bottom of the cilinder: (Now i use: `viewPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition);` to set x and y cordinates of the menu)
I want that A, B menu appear at the center of the cilinder or where i click!
Answer by Sixakoo_ · Dec 15, 2012 at 03:18 AM
Hello,
This is how to make the button appear when you click the object, put the script on the object you want to be clicked: -
var showMenu : boolean;
var mousePosition : Vector2;
var mouseX : int;
var mouseY : int;
function OnMouseUp(){
mouseX=Input.mousePosition.x;
mouseY=Screen.height-Input.mousePosition.y;
showMenu=!showMenu;
}
function OnGUI(){
if(showMenu==true){
if(GUI.Button(Rect(mouseX,mouseY,100,20),"a")){
}
if(GUI.Button(Rect(mouseX,mouseY+30,100,20),"b")){
}
}
}
Hope this helps!
Did you remember to set the show$$anonymous$$enu boolean to true?
I already test this out and no problem. Have you attached the script to the object yet? $$anonymous$$ake sure it's the object you want to make the menu appear and has a collider so the mouse can interact with it.
Your answer
Follow this Question
Related Questions
Destroy objects by clicking on them 1 Answer
Object Movement via Mouse Click? 3 Answers
OnMouseUp() Click Display Effect. 1 Answer
Destroy object using mouse click(raycast to detect collision) 2 Answers
Mouse Click and Spawn object 4 Answers