Beispiel #1
0
    ///<summary>Updates the Bomb item usage every frame, including cooldown timer, checking input and updating the UI.</summary>
    private void UpdateBomb()
    {
        bombCooldownTimer -= Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.Alpha3) &&
            bombCooldownTimer <= 0 &&
            bombCount > 0)
        {
            bombCooldownTimer = bombCooldown;
            bombCount--;

            Collider2D[] targets = Physics2D.OverlapCircleAll(transform.position, bombRadius, bombLayer);
            foreach (Collider2D target in targets)
            {
                if (target.CompareTag(bombTargetTag))
                {
                    Destroy(target.gameObject);
                }
            }
        }

        float progress = bombCooldownTimer / bombCooldown;

        bombDisplay.UpdateDisplay(progress, bombCount);
    }
Beispiel #2
0
    ///<summary>Updates the Energy Drink item usage every frame, including cooldown timer, checking input and updating the UI.</summary>
    private void UpdateEnergyDrink()
    {
        energyDrinkCooldownTimer -= Time.deltaTime;
        energyDrinkDurationTimer -= Time.deltaTime;

        if (energyDrinkDurationTimer <= 0)
        {
            energyDrinkActive = false;
        }

        if (Input.GetKeyDown(KeyCode.Alpha1) &&
            energyDrinkCooldownTimer <= 0 &&
            energyDrinkCount > 0)
        {
            energyDrinkCooldownTimer = energyDrinkCooldown;
            energyDrinkDurationTimer = energyDrinkDuration;
            energyDrinkCount--;
            energyDrinkActive = true;
        }

        float progress = energyDrinkCooldownTimer / energyDrinkCooldown;

        energyDrinkDisplay.UpdateDisplay(progress, energyDrinkCount);
    }
Beispiel #3
0
    ///<summary>Updates the Stun Gun item usage every frame, including cooldown timer, checking input and updating the UI.</summary>
    private void UpdateStunGun()
    {
        stunGunCooldownTimer -= Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.Alpha2) &&
            stunGunCooldownTimer <= 0 &&
            stunGunCount > 0)
        {
            stunGunActive            = !stunGunActive;
            stunGunIndicator.enabled = stunGunActive;
        }

        if (stunGunActive)
        {
            Vector2        mousePosition  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2        mouseDirection = mousePosition - (Vector2)transform.position;
            RaycastHit2D[] hits           = Physics2D.RaycastAll(transform.position, mouseDirection, stunGunRange, stunGunLayer);

            // display an indicator beam while active
            bool hitWall = false;
            foreach (RaycastHit2D hit in hits)
            {
                GameObject target = hit.collider.gameObject;
                if (target.CompareTag("Wall"))
                {
                    hitWall = true;
                    stunGunIndicator.SetPosition(0, transform.position);
                    stunGunIndicator.SetPosition(1, target.transform.position);
                    break;
                }
            }

            if (!hitWall)
            {
                Vector2 targetPos = (Vector2)transform.position + mouseDirection * stunGunRange;
                stunGunIndicator.SetPosition(0, transform.position);
                stunGunIndicator.SetPosition(1, targetPos);
            }

            if (Input.GetButtonDown("Fire1"))
            {
                stunGunActive            = false;
                stunGunIndicator.enabled = false;
                stunGunCooldownTimer     = stunGunCooldown;
                stunGunCount--;

                foreach (RaycastHit2D hit in hits)
                {
                    GameObject target = hit.collider.gameObject;
                    if (target.CompareTag("Wall"))
                    {
                        break;
                    }
                    if (target.CompareTag(stunGunTargetTag))
                    {
                        Enemy enemy;
                        if (target.TryGetComponent <Enemy>(out enemy))
                        {
                            enemy.Stun(stunGunDuration);
                        }
                    }
                }
            }
        }

        float progress = stunGunCooldownTimer / stunGunCooldown;

        stunGunDisplay.UpdateDisplay(progress, stunGunCount);
    }