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

public class Spirits_Float : MonoBehaviour
{
    private bool isRise = true;
    public float maxHeight, minHeight;
    private float height;               //升到哪个高度后停止
    private float curHeight;
    private float speed = 1;
    private Vector3 origPos;

    private void Start()
    {
        origPos = transform.position;
        curHeight = origPos.y;
        height = Random.Range(minHeight, maxHeight);
        GetComponent<Demonic>().flyHeight = height;
    }

    private void MoveToHeight()
    {
        curHeight = Mathf.SmoothDamp(curHeight, height, ref speed, 0.02f);
        transform.position = new Vector3(origPos.x, curHeight, origPos.z);
    }

    private void Update()
    {
        if (isRise)
        {
            MoveToHeight();
            if (curHeight - height <= 0.02f && curHeight - height >= -0.02f)
            {
                isRise = false;
                curHeight = height;
                transform.position = new Vector3(origPos.x, height, origPos.z);
                this.enabled = false;
            }
        }
    }
}
