예제 #1
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.CompareTag("PowerUp"))
     {
         currentPowerUp = col.GetComponent <PowerUpPickup> ().myPowerUpType;
         Destroy(col.gameObject);
         Destroy(Instantiate(pickUpSound), 4f);
     }
 }
예제 #2
0
    void Update()
    {
        if (currentPowerUp == PowerUpPickup.PowerUps.NONE)
        {
            return;
        }

        if (Input.GetKeyDown(dv.GetPowerUpKey(tag)))
        {
            switch (currentPowerUp)
            {
            case PowerUpPickup.PowerUps.OBSTACLE:
                GameObject.FindGameObjectWithTag("Spawner").GetComponent <Spawner> ().SpawnObstacle();
                break;

            case PowerUpPickup.PowerUps.RANDOM_DIRECTION:
                GameObject.FindGameObjectWithTag("Ball").GetComponent <BallController> ().RandomizeDirection();
                break;

            case PowerUpPickup.PowerUps.SHIELD:
                if (tag == "Player 1")
                {
                    GameObject.FindGameObjectWithTag("Goal 1").GetComponent <GoalHandler> ().AddShield();
                }
                else
                {
                    GameObject.FindGameObjectWithTag("Goal 2").GetComponent <GoalHandler> ().AddShield();
                }
                break;

            case PowerUpPickup.PowerUps.SPEED_BALL:
                GameObject.FindGameObjectWithTag("Ball").GetComponent <BallController> ().SpeedBoost();
                break;
            }

            currentPowerUp = PowerUpPickup.PowerUps.NONE;
        }
    }