コード例 #1
0
 void OnTriggerEnter2D(Collider2D col)
 {
     //Debug.Log("Hit!");
     if (col.gameObject.tag == "shield")
     {
         setPowerUpTimer(5);
         leftBallAura.sprite  = shieldAura;
         rightBallAura.sprite = shieldAura;
         leftBallAura.gameObject.SetActive(true);
         rightBallAura.gameObject.SetActive(true);
         //Debug.Log("Hit Shield!");
         ActivateShield();
         Invoke("DeactivateShield", 5.0f);
         StartCoroutine(fadeOut(leftBallAura, 5f));
         StartCoroutine(fadeOut(rightBallAura, 5f));
         col.gameObject.SetActive(false);
     }
     else if (col.gameObject.tag == "reverse")
     {
         setPowerUpTimer(5);
         //leftBallAura.sprite = reverseControlsAura; //buggy
         //rightBallAura.sprite = reverseControlsAura;
         //leftBallAura.gameObject.SetActive(true);
         //rightBallAura.gameObject.SetActive(true);
         //StartCoroutine(fadeOut(leftBallAura, 5f));
         //StartCoroutine(fadeOut(rightBallAura, 5f));
         //Debug.Log("Hit reverse!");
         ActivateReverseMode();
         Invoke("DeactivateReverseMode", 5.0f);
         col.gameObject.SetActive(false);
     }
     else if (col.gameObject.tag == "explosive")
     {
         //Debug.Log("Hit explosive");
         col.gameObject.SetActive(false);
         poolingController.StartExplosions();
         PowerUpControl.ActivateExplosive();
         PowerUpControl.Invoke("CreatePowerUp", 7f); //change spawn time
     }
     else if (col.gameObject.tag == "reverse-direction")
     {
         //Debug.Log("Hit reverse direction");
         //leftBallAura.sprite = reverseDirectionAura;
         //rightBallAura.sprite = reverseDirectionAura;
         col.gameObject.SetActive(false);
         ActivateReverseDirection();
     }
     else if (col.gameObject.tag == "boost")
     {
         col.gameObject.SetActive(false);
         leftBallAura.sprite  = shieldAura;
         rightBallAura.sprite = shieldAura;
         leftBallAura.color   = leftBallAura.material.color;
         rightBallAura.color  = rightBallAura.material.color;
         leftBallAura.gameObject.SetActive(true);
         rightBallAura.gameObject.SetActive(true);
         ActivateBoost();
         Invoke("DeactivateBoost", 2.0f);
     }
     if (col.gameObject.tag == "left" || col.gameObject.tag == "right")    // Checks if the player hits to the obstacles.
     {
         if (PowerUp.hasShield == false)
         {
             GameController.isGameOver = true;
             gameController.GameOver();
         }
     }
 }