using UnityEngine;
using UnityEngine.UIElements;

public class ArcanoidBall : MonoBehaviour
{

    public float speed = 5f;
    public bool inMove;

    Rigidbody rb;

    public void RunBall()
    {
        float x = Random.Range(0, 2) == 0 ? -1 : 1;
        rb.velocity = new Vector3(x * speed, speed, 0f);
    }

    public void StopBall()
    {
        rb.velocity = new Vector3(0, 0, 0);
        transform.position = new Vector3(0, -3, 0);
    }

    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(collision.gameObject.name == "Lose")
        {
            GameManager.instance.lives--;
            GameManager.instance.UpdateUI();
            StopBall();
            GameManager.instance.gameRun = false;
            if (GameManager.instance.lives < 0)
            {
                GameManager.instance.EndGame(false);
                gameObject.GetComponent<Renderer>().enabled = false;
            }
        }
    }
}