SHOW:
|
|
- or go back to the newest paste.
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 | void Update() | |
25 | { | |
26 | if(rb.velocity == new Vector3(0, 0, 0)) | |
27 | { | |
28 | inMove = false; | |
29 | } else | |
30 | { | |
31 | inMove = true; | |
32 | } | |
33 | } | |
34 | ||
35 | private void Start() | |
36 | { | |
37 | rb = GetComponent<Rigidbody>(); | |
38 | } | |
39 | ||
40 | private void OnCollisionEnter(Collision collision) | |
41 | { | |
42 | if(collision.gameObject.name == "Lose") | |
43 | { | |
44 | if(GameManager.instance.lives < 0) | |
45 | { | |
46 | GameManager.instance.EndGame(false); | |
47 | Debug.Log("Game Over"); | |
48 | gameObject.GetComponent<Renderer>().enabled = false; | |
49 | } else | |
50 | { | |
51 | GameManager.instance.lives--; | |
52 | GameManager.instance.UpdateUI(); | |
53 | StopBall(); | |
54 | } | |
55 | ||
56 | } | |
57 | } | |
58 | } |