Advertisement
Guest User

ArcanoidBall

a guest
May 10th, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | Gaming | 0 0
  1.  
  2. using UnityEngine;
  3.  
  4. public class ArcanoidBall : MonoBehaviour
  5. {
  6.     //Prędkość piłki
  7.     public float speed = 5f;
  8.  
  9.     //Funkcja nadająca prędkość
  10.     public void RunBall()
  11.     {
  12.         //Losowanie kierunku
  13.         float x = Random.Range(0, 2) == 0 ? -1 : 1;
  14.         GetComponent<Rigidbody>().velocity = new Vector3(x * speed, speed, 0f);
  15.     }
  16.  
  17.     //Zatrzymanie ruchu
  18.     public void StopBall()
  19.     {
  20.         GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0);
  21.     }
  22.  
  23.     private void Start()
  24.     {
  25.         //Uruchomienie na start, potem usuniemy
  26.         //RunBall();
  27.     }
  28.  
  29.     //Sprawdzenie czy kolidujemy z miejscem zniszczenia
  30.     private void OnCollisionEnter(Collision collision)
  31.     {
  32.         if(collision.gameObject.name == "Lose")
  33.         {
  34.             GameManager.instance.EndGame(false);
  35.             Debug.Log("Koniec Gry");
  36.             this.gameObject.GetComponent<Renderer>().enabled = false;
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement