예제 #1
0
    public void Remove(Powerup powerup)
    {
        if (powerup.type == PickupType.Shield)
        {
            shieldPowerup = (ShieldPowerup)powerup;

            if (shieldPowerup.currentHealth <= 0)
            {
                if (shieldPowerup.visualModifier)
                {
                    RestoreMaterial(tankRenderer, shieldPowerup);
                }
                shieldPowerup.Deactivate(tankData);
                activePowerups[shieldPowerup.type] = null;
            }
        }

        // Assemble a list of expired powerups
        if (powerup.duration <= 0)
        {
            if (powerup.visualModifier)
            {
                RestoreMaterial(tankRenderer, powerup);
            }

            powerup.Deactivate(tankData);
            activePowerups[powerup.type] = null;
        }
    }
예제 #2
0
 //Called when the player enters a trigger, and gives a reference to said trigger collider
 private void OnTriggerEnter(Collider other)
 {
     //When the player touches a powerup, if the powerup is active, then the player gets that powerup and deactivates it
     if (other.gameObject.CompareTag("Power Up"))
     {
         GameObject powerUp       = other.gameObject;
         Powerup    powerUpScript = powerUp.GetComponent <Powerup>();
         if (powerUpScript.isActive)
         {
             powerUpScript.Deactivate();
             activePowerup = powerUp.name;
             SetPowerupText();
         }
     }
     //Upon touching a gem, disable it, add it to a list so it can be reenabled if the player resets, and increment the number of gems collected
     else if (other.gameObject.CompareTag("Gem"))
     {
         currentGems++;
         SetGemText();
         other.gameObject.SetActive(false);
         recentGems.Add(other.gameObject);
     }
     //When reaching a checkpoint, set it as the active checkpoint, and play a particle effect if it isn't already the active checkpoint
     else if (other.gameObject.CompareTag("Checkpoint"))
     {
         if (other.gameObject != activeCheckpoint.gameObject)
         {
             Instantiate(checkpointParticles, other.gameObject.transform.position, Quaternion.Euler(-90, 0, 0));
         }
         activeCheckpoint = other.gameObject.transform;
         //Clearing the list of recently collected gems essentially "saves" them as being permanently collected
         recentGems.Clear();
         usedRotators.Clear();
     }
     //End the level when the player reaches the finish
     else if (other.gameObject.CompareTag("Finish"))
     {
         EndLevel();
     }
 }