using UnityEngine;
using UnityEngine.SceneManagement;

public class Human : MonoBehaviour 
{
    public Vector2 StartPos;
    private HumanAI ai;

	void Start () 
	{
        ai = GetComponent<HumanAI>();
        HumanControl.AddHuman(transform);
        DontDestroyOnLoad(gameObject);

        SceneManager.sceneLoaded += OnSceneLoaded;
    }

    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        transform.position = StartPos + Random.insideUnitCircle.normalized;
        if (ai != null)
            ai.ClearGoal();
    }

    void OnDestroy()
    {
        SceneManager.sceneLoaded -= OnSceneLoaded;
    }
}
