// #########################################################
    // # ---------------------- UPDATE ----------------------- #
    // #########################################################

    public override void Tick()
    {
        base.Tick();

        if (owner != null)
        {
            if (!owner.gm.isPaused)
            {
                Motion();


                // Update Canvas
                if (guiCanvas.enabled)
                {
                    // Health
                    healthText.text = entity.GetCurrentHealth() + " / " + entity.GetMaxHealth();

                    float currentHealth = entity.GetCurrentHealth();
                    float maxHealth     = entity.GetMaxHealth();
                    healthBar.fillAmount = currentHealth / maxHealth;

                    // Resource
                    resourceText.text = entity.GetCurrentResource() + " / " + entity.GetMaxResource();

                    float currentResource = entity.GetCurrentResource();
                    float maxResource     = entity.GetMaxResource();
                    resourceBar.fillAmount = currentResource / maxResource;
                }

                // GCD Timer
                if (delay > 0)
                {
                    delay -= Time.deltaTime;
                }
                if (delay < 0)
                {
                    delay = 0;
                }
            }
        }
    }
Пример #2
0
    // #########################################################
    // # ---------------------- UPDATE ----------------------- #
    // #########################################################

    public override void Tick()
    {
        base.Tick();

        if (owner != null)
        {
            if (!owner.gm.isPaused)
            {
                if (!disableControls)
                {
                    Motion();
                }


                // TARGETING SYSTEM
                if (activeTargetIndicator != null)
                {
                    Ray ray = cam.ScreenPointToRay(Input.mousePosition);

                    RaycastHit hitInfo;
                    if (Physics.Raycast(ray, out hitInfo))
                    {
                        // Get Collision Data
                        ///////////////////////////////////////////////////////////////////////////////////////////////

                        activeTargetIndicator.transform.position = hitInfo.point + hitInfo.normal * 0.1f;
                    }
                }

                // CHANNELLING
                if (channelledAbility != null)
                {
                    channelingBar.enabled  = true;
                    channelingText.enabled = true;

                    if (channelTimer > 0)
                    {
                        channelTimer -= Time.deltaTime;
                        isChanneling  = true;

                        channelingText.text      = channelledAbility.GetName() + " : " + Mathf.Round(channelTimer * 100) / 100;
                        channelingBar.fillAmount = (channelTimer / 2.5f);
                    }

                    if (channelTimer <= 0)
                    {
                        RPG3_AbilitySettings settings = new RPG3_AbilitySettings();
                        switch (channelledAbility.GetAbilityMode())
                        {
                        case RPG3_AbilityMode.Targeted:
                            settings = RPG3_AbilitySettings.Initialize(this, channelTarget);
                            break;

                        case RPG3_AbilityMode.Positional:
                            settings = RPG3_AbilitySettings.Initialize(this, abilityTargetPoint);
                            break;

                        case RPG3_AbilityMode.Self:
                            settings = RPG3_AbilitySettings.Initialize(this, channelTarget);
                            break;
                        }

                        channelledAbility.Effect(settings);

                        channelledAbility      = null;
                        channelTarget          = null;
                        channelingBar.enabled  = false;
                        channelingText.enabled = false;
                    }
                }

                hotbar.HotkeyTracker();

                if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    // If a UI element was pressed, break out.
                    if (uiRaycaster.Raycast().Count > 0)
                    {
                        return;
                    }

                    if (abilityBeingTargeted == null)
                    {
                        // Clear the active target if worldspace was clicked
                        if (targetController != null || targetEntity != null)
                        {
                            targetController = null;
                            targetEntity     = null;
                        }
                    }


                    // if the UI was not pressed, raycast to world position
                    Ray ray = cam.ScreenPointToRay(Input.mousePosition);

                    RaycastHit hitInfo;
                    if (Physics.Raycast(ray, out hitInfo))
                    {
                        // Get Collision Data
                        ///////////////////////////////////////////////////////////////////////////////////////////////

                        GameObject targetHit = hitInfo.collider.gameObject;
                        Debug.Log(targetHit);

                        // Activate an ability that's being targeted
                        if (abilityBeingTargeted != null)
                        {
                            if (activeTargetIndicator != null)
                            {
                                Destroy(activeTargetIndicator);
                                activeTargetIndicator = null;
                            }

                            RPG3_AbilitySettings settings = RPG3_AbilitySettings.Initialize(this, hitInfo.point);
                            abilityBeingTargeted.Activate(settings);

                            abilityTargetPoint = hitInfo.point;
                            abilityBeingTargeted.isTargeting = false;
                            abilityBeingTargeted             = null;
                        }


                        // Selection Command
                        if (targetHit.GetComponentInParent <TPS_Controller>() != null)
                        {
                            targetController = targetHit.GetComponentInParent <TPS_Controller>();
                        }

                        if (targetHit.GetComponentInParent <TPS_Entity>() != null)
                        {
                            //Debug.Log(hitInfo.collider.gameObject.name + " selected");

                            targetEntity = targetHit.GetComponentInParent <TPS_Entity>();

                            ///////////////////////////////////////////////////////////////////////////////////////////////
                        }
                    }
                }

                if (Input.GetKeyDown(KeyCode.Mouse1))
                {
                    // Activate an ability that's being targeted
                    if (abilityBeingTargeted != null)
                    {
                        if (!isChanneling)
                        {
                            if (activeTargetIndicator != null)
                            {
                                Destroy(activeTargetIndicator);
                                activeTargetIndicator = null;
                            }

                            abilityTargetPoint = Vector3.zero;
                            abilityBeingTargeted.isTargeting = false;
                            abilityBeingTargeted             = null;
                        }
                    }
                }

                // Update Canvas
                if (guiCanvas.enabled)
                {
                    // Health
                    healthText.text = entity.GetCurrentHealth() + " / " + entity.GetMaxHealth();

                    float currentHealth = entity.GetCurrentHealth();
                    float maxHealth     = entity.GetMaxHealth();
                    healthBar.fillAmount = currentHealth / maxHealth;

                    // Resource
                    resourceText.text = entity.GetCurrentResource() + " / " + entity.GetMaxResource();

                    float currentResource = entity.GetCurrentResource();
                    float maxResource     = entity.GetMaxResource();
                    resourceBar.fillAmount = currentResource / maxResource;

                    // Target System
                    if (targetEntity != null)
                    {
                        if (!targetInfoDisplay.activeInHierarchy)
                        {
                            targetInfoDisplay.SetActive(true);
                        }

                        // Health
                        targetHealthText.text = targetEntity.GetCurrentHealth() + " / " + targetEntity.GetMaxHealth();

                        float currentTargetHealth = targetEntity.GetCurrentHealth();
                        float maxTargetHealth     = targetEntity.GetMaxHealth();
                        targetHealthBar.fillAmount = currentTargetHealth / maxTargetHealth;

                        // Resource
                        targetResourceText.text = targetEntity.GetCurrentResource() + " / " + targetEntity.GetMaxResource();

                        float currentTargetResource = targetEntity.GetCurrentResource();
                        float maxTargetResource     = targetEntity.GetMaxResource();
                        targetResourceBar.fillAmount = currentTargetResource / maxTargetResource;
                    }

                    else
                    {
                        if (targetInfoDisplay.activeInHierarchy)
                        {
                            targetInfoDisplay.SetActive(false);
                        }
                    }
                }
            }
        }
    }