Advertisement
Guest User

ArkanoidBall

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