View difference between Paste ID: 3br8NGWg and HGA9GwCz
SHOW: | | - or go back to the newest paste.
1
using UnityEngine;
2
3
public class ArcanoidBall : MonoBehaviour
4
{
5
    //ball speed
6
    public float speed = 5f;
7
8
    //function which adds speed to the ball
9
    public void RunBall()
10
    {
11
        //Randomizing direction
12
        float x = Random.Range(0, 2) == 0 ? -1 : 1;
13
        GetComponent<Rigidbody>().velocity = new Vector3(x * speed, speed, 0f);
14
    }
15
16
    //Stopping movement
17
    public void StopBall()
18
    {
19
        GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0);
20
    }
21
22
    private void Start()
23
    {
24
        //Starting the ball when the game start. Can be removed later
25
        //RunBall();
26
    }
27
28
    //Checking if the ball collided with Lose cube
29
    private void OnCollisionEnter(Collision collision)
30
    {
31
        if(collision.gameObject.name == "Lose")
32
        {
33
            GameManager.instance.EndGame(false);
34
            Debug.Log("Game Over");
35
            this.gameObject.GetComponent<Renderer>().enabled = false;
36
        }
37
    }
38
}