- Home /
Centering Radial Menu
I'm attempting to make a radial menu whose center is that of a specified game object. Here is my code so far
using UnityEngine;
using System.Collections;
public class RadialMenu : MonoBehaviour {
public int buttonCount; //The number of buttons to be displayed
public float radius; //The radius of the circle
public GameObject objectOfCenter;
//C#
void OnGUI()
{
float angleStep = Mathf.PI*2.0f / buttonCount;
Vector2 circleCenter = new Vector2(objectOfCenter.transform.position.x,objectOfCenter.transform.position.y);
// Set the circle radius
for (int i = 0; i < buttonCount; i++)
{
Rect R = new Rect(0,0,40,20);
R.x = circleCenter.x + Mathf.Cos(angleStep*i)*radius - R.width/2;
R.y = circleCenter.y + Mathf.Sin(angleStep*i)*radius - R.height/2;
}
}
}
I feel like it should work, but when I run the game I get this.
That ring of buttons should be centered around the center point of that big ring on the right.
objectOfCenter = big circle on the right.
Any ideas?
untitled.png
(125.1 kB)
Comment
Your answer
Follow this Question
Related Questions
Radial Menu - Mouse Selection 1 Answer
Bringing window to back GUI.BringWindowToBack() 0 Answers
Menu gui with background image 0 Answers
Why is only my last for-loop-button triggering? 1 Answer
Tutorials for 2D game GUI 2 Answers