Ejemplo n.º 1
0
 void OnCollisionEnter(Collision col)
 {
     if (col.collider.tag == "Player")
     {
         rb.velocity = rb.velocity.normalized * speed;
         float num       = (col.collider.transform.position.y + (col.collider.bounds.size.y / 2) - transform.position.y);
         float Normalnum = (num / (col.collider.bounds.size.y / 2));
         if (Normalnum > 1.2)
         {
             rb.velocity = new Vector3(rb.velocity.x, -10, rb.velocity.z);
         }
         else if (Normalnum < 0.8)
         {
             rb.velocity = new Vector3(rb.velocity.x, 10, rb.velocity.z);
         }
         speed++;
     }
     if (col.collider.gameObject.name == "Player 1 Wall")
     {
         player2.score++;
         text.text = "Player 1: " + player2.score;
         if (player2.score == winScore)
         {
             play.setWinner("Player 1 wins");
             SceneManager.LoadScene("Win Scene");
         }
         Respawn();
     }
     else if (col.collider.gameObject.name == "Player 2 Wall")
     {
         player1.score++;
         text2.text = "Player 2: " + player1.score;
         if (player1.score == winScore)
         {
             play.setWinner("Player 2 wins");
             SceneManager.LoadScene("Win Scene");
         }
         Respawn();
     }
 }