Exemple #1
0
    void Update()
    {
        if (unit == null)
        {
            Destroy(gameObject, 0);
            return;
        }
        status = unit.GetHealth();
        bar.transform.localScale = new Vector2(status / (float)unit.GetMaxHealth(), bar.transform.localScale.y);

        target = new Vector2(unit.transform.position.x, unit.transform.position.y - .65f);
        fullBar.transform.position = target;
    }
    /**
     * <summary>
     * Select a unit
     * </summary>
     *
     * <returns>
     * void
     * </returns>
     */
    public static void Select(GameObject unit)
    {
        if (unit.GetComponent <UnitBehaviour>() == null)
        {
            throw new Exception(unit.name + " " + "is not a unit type");
        }

        // Clear previous units
        UnitsManagerBehaviour.UnselectGameObjects();

        // Unselect resource
        if (ResourcesManagerBehaviour.SelectedResource != null)
        {
            ResourcesManagerBehaviour.UnselectResource();
        }

        UnitBehaviour unitBehaviour = unit.GetComponent <UnitBehaviour>();

        if (unitBehaviour is ISelectableUnit)
        {
            UnitsManagerBehaviour.SelectedUnits.Add(unit);
            unitBehaviour.SetSelect(true);

            Self.infoComponentPanel.SetActive(true);

            // Show info component panel
            Self.infoComponentPanel
            .transform
            .Find("Single")
            .gameObject
            .SetActive(true);

            // Hide multiple
            Self.infoComponentPanel
            .transform
            .Find("Multiple")
            .gameObject
            .SetActive(false);

            UnitUI unitUI = unitBehaviour.GetUI().GetComponent <UnitUI>();

            InfoComponentPanelUI infoComponentPanelUI = Self.infoComponentPanel.GetComponent <InfoComponentPanelUI>();
            infoComponentPanelUI.SetName(unit.name);
            infoComponentPanelUI.SetHealth(unitBehaviour.GetHealth(), unitBehaviour.GetMaxHealth());
            infoComponentPanelUI.SetIcon(unitUI.GetIcon());

            // Show action component panel
            Self.actionComponentPanel.SetActive(true);
        }
    }
Exemple #3
0
 void Update()
 {
     SetHealth(_unit.GetHealth() / _unit.Data.maxHealth);
 }