using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class PlayerWidget : MonoBehaviour {
    private Transform jointTransform;

    public void Awake() {
        transform.localScale = Vector3.zero;
    }

    public void SetPlayerTransform(Transform transform) {
        jointTransform = transform;
    }

    public void Show(float delay=0.0f) {
        LeanTween.scale(gameObject, Vector3.one, 0.1f).setDelay(delay);
        Invoke("Hide",3.0f+delay);
    }

    public void Hide() {
        LeanTween.scale(gameObject, Vector3.zero, 0.1f);
    }

    private void Update() {
        if (jointTransform == null) {
            return; }

        Vector2 screenPos = Camera.main.WorldToScreenPoint(jointTransform.position);
        screenPos -= new Vector2(Screen.width / 2,Screen.height/2);
        transform.localPosition = screenPos;
    }
}
