public void SpawnMenu(ClickToUpgrade obj)
    {
        //Instantiate radial menu prefab
        RadialMenu newMenu = Instantiate(menuPrefab) as RadialMenu;

        newMenu.transform.SetParent(transform, false);
        newMenu.transform.position = Input.mousePosition; //spawn the menu where the mouse is
        newMenu.SpawnButtons(obj);                        //spawn buttons
    }
Beispiel #2
0
    /// **************
    /// Zis is ze button-spawning method
    /// **************
    public void SpawnButtons(ClickToUpgrade obj)
    {
        //ClickToUpgrade is the reference (ie obj refers to ClickToUpgrade)

        for (int i = 0; i < obj.options.Length; i++)
        {
            RadialButton newButton = Instantiate(buttonPrefab) as RadialButton;
            newButton.transform.SetParent(transform, false);

            //Calculation of angle of rotation (360 degrees / no of buttons) for each button placement
            float theta = (2 * Mathf.PI / obj.options.Length) * i;
            float xPos  = Mathf.Sin(theta);                                           //oh look jolly more math
            float yPos  = Mathf.Cos(theta);
            newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * radius; //set position based on calculations made

            //Setting button elements as listed in ClickToUpgrade's options
            newButton.circle.color = obj.options[i].color;
            newButton.icon.sprite  = obj.options[i].iconSprite;
            newButton.actionName   = obj.options[i].actionName;
            newButton.menu         = this; //reference to where and what is ze menu
        }
    }