Ejemplo n.º 1
0
    public void OnTriggerStay(Collider other)
    {
        if (other.tag == Tags.CRATE)
        {
            crateManager.RemoveCrate(other.gameObject);
            Destroy(other.gameObject);

            HealthScript health = null;

            if (gameObject.GetComponent <HealthScript>())
            {
                health = gameObject.GetComponent <HealthScript>();
            }
            else if (gameObject.GetComponentInParent <HealthScript>())
            {
                health = gameObject.GetComponentInParent <HealthScript>();
            }

            if (health != null)
            {
                health.ApplyRegeneration(regenTimePerCrate, regenAmtPerSec);
            }
        }
        else if (other.tag == Tags.POWERUP)
        {
            PowerupInfo info = other.gameObject.GetComponent <PowerupInfo>();
            _powerupActivator.ActivatePowerup(info);

            Destroy(other.gameObject);
        }
    }
    public void ActivatePowerup(PowerupInfo powerupInfo)
    {
        _powerupTimer  = powerupInfo.duration;
        _activePowerup = powerupInfo.powerupType;

        switch (_activePowerup)
        {
        case PowerupInfo.Type.FasterReload:
            for (int i = 0; i < _cannonballSpawners.Length; i++)
            {
                _cannonballSpawners[i].ChangeCooldown(powerupInfo.reloadTimeFactor);
            }

            _bombSpawner.ChangeCooldown(powerupInfo.reloadTimeFactor);
            break;

        case PowerupInfo.Type.DamageBoost:
            for (int i = 0; i < _cannonballSpawners.Length; i++)
            {
                _cannonballSpawners[i].ChangeDamage(powerupInfo.damageBoostFactor);
            }

            _bombSpawner.ChangeDamage(powerupInfo.reloadTimeFactor);
            break;

        case PowerupInfo.Type.MovementSpeedBoost:
            _shipMovement.ChangeMaxSpeed(powerupInfo.movementSpeedBoostFactor);
            break;

        case PowerupInfo.Type.TemporaryBonusHP:
            _healthScript.AddTempHP(powerupInfo.bonusHP);
            break;

        case PowerupInfo.Type.AutoHPRegen:
            _healthScript.ApplyRegeneration(powerupInfo.duration, powerupInfo.regenerationAmountPerSec);
            break;

        default:
            break;
        }
    }
Ejemplo n.º 3
0
    public void UpdateState()
    {
        //First try to go for the nearest Crate
        Transform nearestCrate = CrateManager.GetClosestCrate(transform.position).transform;
        Vector3   deltaVec     = nearestCrate.position - transform.position;

        if (deltaVec.magnitude < Behaviour.CrateDetectionRange)
        {
            Behaviour.SetTargetDestination(nearestCrate.position);

            if (deltaVec.magnitude < Behaviour.CratePickupRange)
            {
                CrateManager.RemoveCrate(nearestCrate.gameObject);
                Destroy(nearestCrate.gameObject);
                health.ApplyRegeneration(RegenDuration, RegenPerSecond);
            }
        }
        //If all the crates are out of range, try to hide in the middle of the swarm
        else
        {
            Behaviour.SetTargetDestination(Behaviour.Flocking.calculateLocalSwarmCenter());
        }
    }