using UnityEngine;
using System.Collections;

public class FollowPlayerScript : MonoBehaviour 
{

    public PlayerMovement playerScript;

	// Use this for initialization
	void Start () {
	
	}


    protected virtual bool GetPlayerScript()
    {
        GameObject go = GameObject.Find("PlayerMans");
        if (go != null)
        {
            playerScript = go.GetComponent<PlayerMovement>();
        }

        return playerScript != null;
    }


	// Update is called once per frame
	void Update ()
	{
	    if (playerScript == null && !GetPlayerScript())
	        return;

	    if (playerScript.bIAmDead)
	        return;

        Vector3 vPos = transform.position;
        if (playerScript != null)
            vPos.x = playerScript.transform.position.x;

        float fPlayerY = playerScript.transform.position.y;

	    if (fPlayerY < vPos.y - 3)
	        vPos.y = fPlayerY + 3;
        else if (fPlayerY > vPos.y + 1)
            vPos.y = fPlayerY - 1;

        transform.position = vPos;
	}
}
