using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class BallScript : MonoBehaviour {

    bool offscreen = false;

	// Use this for initialization
	void Start () {
		
	}
	
    // Update is called once per frame
    void Update()
    {

        // if off the screen
        if ((transform.position.x > 2.4 || transform.position.x < -2.4) && !offscreen)
        {
            GetComponent<AudioSource>().Play();
            Invoke("RestartGame", 1.0f);
            offscreen = true;

        }
        if ((transform.position.y > 1.6 || transform.position.y < -1.6) && !offscreen)
        {
            GetComponent<AudioSource>().Play();
            Invoke("RestartGame", 1.0f);
            offscreen = true;

        }
    }

    public void MoveUsingPoint(Vector2 upPoint)
    {
        Vector2 direction = (Vector2)transform.position - upPoint;
        direction.Normalize();
        GetComponent<Rigidbody2D>().velocity = direction * 2.0f;
    }

    public void RestartGame() {
        SceneManager.LoadScene("Level-" + GameScript.level); 
    }
}
