Hi.

I’m making a radial context menu for a point and click game which distributes the required number of UI buttons around the transform.position of an object. Everything is working except for one issue: The origin or center of the menu needs to converted from the tranform.position of the object, to a UI position.

I’ve tried so many solutions that I’m probably missing something really simple.

My code is below. If anyone could help it’d be most appreciated. Let me know if you need any further info.

public void CreateMenu()
    {
        if (ICM.currentObj)
        {
            Vector3 origin = ICM.currentObj.transform.position;

           // Vector3 origin = Camera.current.WorldToScreenPoint(ICM.currentObj.transform.position);

            float radius = ICM.currentObj.GetComponent<Collider>().bounds.size.y; 
            int numOfVerbs = verbList.Count;                                       
            int ang = 360 / numOfVerbs;                                            

            //This for loop repeats for each required button in the menu.
            for (int i = 0; i < numOfVerbs; i++)
            {
                int a = 360 / numOfVerbs * i;                                      
                Vector3 pos = Circle(origin, radius, a);                           
                Vector3 insPos = Camera.current.WorldToScreenPoint(pos);          

                //Construct the button
                GameObject vB = Instantiate(verbButton, pos, rot) as GameObject;    //vB = verbButton
                vB.transform.SetParent(canvas.transform, false);                   

                //vB.transform.position = new Vector3(insPos.x, insPos.y, insPos.z);

                vB.GetComponent<Image>().sprite = verbList*.icon;* 

vB.GetComponent().v = verbList*;*
ICM.buttonList.Add(vB);

//debug stuff
Debug.DrawLine(origin, pos, Color.red,2);
}

}
}

//This function takes the position of the ICM.CurrentObj as a centre and generates a point on a circle for each button required.
public Vector3 Circle(Vector3 center, float radius, int a)
{
float ang = a;
Vector3 pos;

//
pos.x = center.x + radius * Mathf.Sin(ang * Mathf.Deg2Rad);
pos.y = center.y + radius * Mathf.Cos(ang * Mathf.Deg2Rad);
pos.z = center.z;
return pos;
}

Camera.WorldToScreenPoint(); might be what you are looking for

var pos = targetobject.position;
var screenpos = Camera.WorldToScreenPoint(pos);

Edit: I see you already did somethin similar at line 7, but commented it. That makes line 5 unnecessary, so you should replace line 5 with line 7.

 public void CreateMenu()
     {
         if (ICM.currentObj)
         {
             //Vector3 origin = ICM.currentObj.transform.position;
 
             Vector3 origin = Camera.current.WorldToScreenPoint(ICM.currentObj.transform.position);

etc

You can use the RectTransformUtility to map world coordinates to RectTransform and back

http://forum.unity3d.com/threads/overlay-canvas-and-world-space-coordinates.291108/