SHOW:
|
|
- or go back to the newest paste.
| 1 | using UnityEngine; | |
| 2 | ||
| 3 | public class ArcanoidBall : MonoBehaviour | |
| 4 | {
| |
| 5 | //Prędkość piłki | |
| 6 | public float speed = 5f; | |
| 7 | ||
| 8 | //Funkcja nadająca prędkość | |
| 9 | public void RunBall() | |
| 10 | {
| |
| 11 | //Losowanie kierunku | |
| 12 | float x = Random.Range(0, 2) == 0 ? -1 : 1; | |
| 13 | GetComponent<Rigidbody>().velocity = new Vector3(x * speed, speed, 0f); | |
| 14 | } | |
| 15 | ||
| 16 | //Zatrzymanie ruchu | |
| 17 | public void StopBall() | |
| 18 | {
| |
| 19 | GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0); | |
| 20 | } | |
| 21 | ||
| 22 | private void Start() | |
| 23 | {
| |
| 24 | //Uruchomienie na start, potem usuniemy | |
| 25 | //RunBall(); | |
| 26 | } | |
| 27 | ||
| 28 | //Sprawdzenie czy kolidujemy z miejscem zniszczenia | |
| 29 | private void OnCollisionEnter(Collision collision) | |
| 30 | {
| |
| 31 | if(collision.gameObject.name == "Lose") | |
| 32 | {
| |
| 33 | GameManager.instance.EndGame(false); | |
| 34 | Debug.Log("Koniec Gry");
| |
| 35 | this.gameObject.GetComponent<Renderer>().enabled = false; | |
| 36 | } | |
| 37 | } | |
| 38 | } | |
| 39 |