Exemplo n.º 1
0
 void OnCollisionEnter2D(Collision2D col)
 {
     audio.Play();
     if (col.gameObject.tag == "Brick" && exploding)
     {
         explode = true;
         StartCoroutine(OffExplodeBall());
     }
     if (col.gameObject.tag == "Player")
     {
         GetComponent <Rigidbody2D>().velocity = new Vector2((transform.position.x - col.gameObject.transform.position.x) / col.gameObject.transform.lossyScale.x, 1).normalized *speed;
     }
     else if (col.gameObject.tag == "Dead Zone")
     {
         Debug.Log(number + ", " + GameStatic.GetBalls());
         if (GameStatic.GetLifes() - 1 <= 0 && number <= 1)
         {
             Debug.Log("koniec");
             GameStatic.SetLifes(GameStatic.GetLifes() - 1);
             gameOver.GetComponent <GameOver>().change = true;
             Destroy(gameObject);
             return;
         }
         else
         {
             if (number > 1)
             {
                 Destroy(gameObject);
                 return;
             }
             else
             {
                 GameStatic.SetLifes(GameStatic.GetLifes() - 1);
                 transform.localPosition = new Vector3(player.position.x, transformY, 0);
                 GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
                 GameObject go = GameObject.FindGameObjectWithTag("Player");
                 go.GetComponent <Player>().ball = gameObject;
                 move = false;
             }
         }
     }
     if (GetComponent <Rigidbody2D>().velocity.y < 0.2f && GetComponent <Rigidbody2D>().velocity.y >= 0)
     {
         GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0.2f) * speed;
     }
     else if (GetComponent <Rigidbody2D>().velocity.y > -0.2f && GetComponent <Rigidbody2D>().velocity.y < 0)
     {
         GetComponent <Rigidbody2D>().velocity = new Vector2(0, -0.2f) * speed;
     }
     if (GetComponent <Rigidbody2D>().velocity.magnitude < 4f && move)
     {
         GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity.normalized *speed;
     }
     if (!move)
     {
         GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
     }
 }
Exemplo n.º 2
0
 void Update()
 {
     score.text = "Score: " + GameStatic.GetAllScore();
     lives.text = "Lifes: " + GameStatic.GetLifes();
 }
Exemplo n.º 3
0
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag == "Player")
     {
         if ((byte)bonus == 0)
         {
             col.gameObject.GetComponent <Player>().Enlarge(0.1F);
         }
         else if ((byte)bonus == 1)
         {
             col.gameObject.GetComponent <Player>().Reduce(0.1F);
         }
         else if ((byte)bonus == 2)
         {
             GameObject[] gos = GameObject.FindGameObjectsWithTag("Ball") as GameObject[];
             foreach (GameObject go in gos)
             {
                 go.GetComponent <Ball>().Disruption();
             }
         }
         else if ((byte)bonus == 3)
         {
             GameStatic.SetLifes(GameStatic.GetLifes() + 1);
         }
         else if ((byte)bonus == 4)
         {
             GameObject[] gos = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[];
             foreach (GameObject go in gos)
             {
                 if (go.CompareTag("Ball"))
                 {
                     go.GetComponent <Ball>().FireBall();
                 }
             }
         }
         else if ((byte)bonus == 5)
         {
             Instantiate(barrier, new Vector3(0, -3.08f, 0.1f), new Quaternion(0, 0, 0, 0));
         }
         else if ((byte)bonus == 6)
         {
             col.gameObject.GetComponent <Player>().Fire();
         }
         else if ((byte)bonus == 7)
         {
             GameObject[] gos = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[];
             foreach (GameObject go in gos)
             {
                 if (go.CompareTag("Ball"))
                 {
                     go.GetComponent <Ball>().ExplodingBall();
                 }
             }
         }
         Destroy(gameObject);
     }
     else if (col.gameObject.tag == "Dead Zone")
     {
         Destroy(gameObject);
     }
 }