Advertisement
giganciprogramowania

l16 ArkanoidBall

May 19th, 2023
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3.  
  4. public class ArcanoidBall : MonoBehaviour
  5. {
  6.  
  7.     public float speed = 5f;
  8.     public bool inMove;
  9.  
  10.     Rigidbody rb;
  11.  
  12.     public void RunBall()
  13.     {
  14.         float x = Random.Range(0, 2) == 0 ? -1 : 1;
  15.         rb.velocity = new Vector3(x * speed, speed, 0f);
  16.     }
  17.  
  18.     public void StopBall()
  19.     {
  20.         rb.velocity = new Vector3(0, 0, 0);
  21.         transform.position = new Vector3(0, -3, 0);
  22.     }
  23.  
  24.     private void Start()
  25.     {
  26.         rb = GetComponent<Rigidbody>();
  27.     }
  28.  
  29.     private void OnCollisionEnter(Collision collision)
  30.     {
  31.         if(collision.gameObject.name == "Lose")
  32.         {
  33.             GameManager.instance.lives--;
  34.             GameManager.instance.UpdateUI();
  35.             StopBall();
  36.             GameManager.instance.gameRun = false;
  37.             if (GameManager.instance.lives < 0)
  38.             {
  39.                 GameManager.instance.EndGame(false);
  40.                 gameObject.GetComponent<Renderer>().enabled = false;
  41.             }
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement