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
 public void Disruption()
 {
     if (number < 7)
     {
         GameObject newObject  = Instantiate(gameObject, transform.position, transform.rotation) as GameObject;
         GameObject newObject2 = Instantiate(gameObject, transform.position, transform.rotation) as GameObject;
         newObject.GetComponent <Ball>().StartMove();
         newObject2.GetComponent <Ball>().StartMove();
         GameStatic.SetBalls((byte)(GameStatic.GetBalls() + 2));
     }
 }
Exemplo n.º 3
0
 void OnDestroy()
 {
     --number;
     GameStatic.SetBalls(GameStatic.GetBalls() - 1);
 }