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

public class GameManager : MonoBehaviour
{
    public static GameManager intance;
    public GameObject BallPrefabs;
    public GameObject LookAtTarget;
    public Animator goalkeeperAnimator;
    public Camera MainCamera;
    //public float distance = ;
    Vector3 offset; 
    private void Awake()
    {
        intance = this;
       
    }

    private void Start()
    {
        MainCamera.transform.position = new Vector3(0, 1.3f, 61.5f);
        offset = MainCamera.transform.position - BallPrefabs.transform.position;
    }
    public void SetUpGame()
    {
        //MainCamera.transform.position = new Vector3 ( Random.Range(-14f,14f),1.3f,Random.Range(55, 65));
        MainCamera.transform.position = new Vector3(0, 1.3f, 61.5f);
        MainCamera.transform.LookAt(LookAtTarget.transform);
        goalkeeperAnimator.gameObject.transform.LookAt(BallPrefabs.transform);
        goalkeeperAnimator.Play("Idle");
        //goalkeeperAnimator.gameObject.transform.LookAt(BallPrefabs.transform);
        Vector3 ballPosition = MainCamera.transform.position - MainCamera.transform.forward * offset.z + MainCamera.transform.up * offset.y;
        ballPosition = new Vector3(ballPosition.x, 0.2f, ballPosition.z);
        //Instantiate(BallPrefabs, MainCamera.transform.position - offset, Quaternion.identity);
        //Instantiate(BallPrefabs, ballPosition, Quaternion.identity);
        //Instantiate(BallPrefabs, new Vector3 (MainCamera.transform.position.x - offset.x , 0.2f, MainCamera.transform.position.z - offset.z), Quaternion.identity);
        //new Vector3(0, 0.2f, 68.38f);
        BallPrefabs.transform.position = ballPosition;
        
        BallPrefabs.SetActive(true);
        BallPrefabs.GetComponent<BallController>().OpenTrain();
    }
}
