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

public class Wave : MonoBehaviour
{

    private Animator anim;

    [SerializeField]
    private Transform goalObject;

    // Start is called before the first frame update
    void Start()
    {
        anim = this.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            var dir = this.transform.TransformDirection(goalObject.position - this.transform.position).normalized;

            dir = Vector3.ProjectOnPlane(dir, Vector3.up);
            float angle = Mathf.Clamp(Vector2.SignedAngle(new Vector2(0, 1), new Vector2(dir.x, dir.z)) / 90, -1, 1);

            anim.SetFloat("WaveBlend", angle);
            anim.SetLayerWeight(1, 1);
            anim.SetTrigger("Wave");
        }

        if (anim.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
        {
            Debug.Log("Idle");
        }
        else if (anim.GetCurrentAnimatorStateInfo(0).IsName("Waving"))
        {
            Debug.Log("Waving");
        }


    }
}
