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

public class NavigateToTransform : MonoBehaviour
{
    public Transform transformGoTo;

    NavMeshAgent navMeshAgent;
    [SerializeField]Animator animator;
    
    // Start is called before the first frame update
    void Awake()
    {
        navMeshAgent = GetComponent<NavMeshAgent>();

        navMeshAgent.updateRotation = false;
        navMeshAgent.updateUpAxis = false;
    }

    private void Start()
    {
        transformGoTo = GameObject.FindGameObjectWithTag("Tower").transform;
    }

    void Update()
    {
        animator.SetFloat("Velocity", navMeshAgent.speed);

        if (navMeshAgent.enabled)
        {
            if (transformGoTo)
            {
                navMeshAgent.SetDestination(transformGoTo.position);
            }
            else
            {
                navMeshAgent.SetDestination(transform.position);
            }
        }

    }

}
