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

public class StackNode : MonoBehaviour
{
    [SerializeField] private float rotationSpeed = 10f;
    [SerializeField] private float descendTime = 0.2f;
    [SerializeField] private float nodeHeight = 1f;
    public int score = 100;

    private Movable movable;
    private float nodeHeightDistance = 0.1f;

    private void Awake()
    {
        movable = gameObject.GetComponent<Movable>();
    }

    void Start()
    {
        GameEvents.instance.onHitEvent += Descend;
    }

    void FixedUpdate()
    {
        transform.localEulerAngles += new Vector3(0f, rotationSpeed * Time.fixedDeltaTime, 0f);
    }

    private void OnDestroy()
    {
        GameEvents.instance.onHitEvent -= Descend;
    }

    public float GetNodeHeight()
    {
        return nodeHeight;
    }

    public float GetNodeHeightDifference()
    {
        return nodeHeightDistance;
    }

    private void Descend()
    {
        movable.SetDestination(movable.targetPosition - new Vector3(0f, nodeHeight + nodeHeightDistance, 0f), descendTime);
    }
}
