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

public class MatureTrigger : MonoBehaviour
{

    public GameObject Shuniupai;

    private float timer = 0;

    public  Vector3 origscale;

    void Start()
    {
        origscale = Shuniupai.transform.localScale;
        Shuniupai.transform.localScale = Vector3.zero;
    }

    void Update()
    {
        
    }
    private void OnTriggerEnter(Collider other)
    {
  
    }
  
    


    private bool isend = false;


    private bool ISA = true;
    private bool ISB = false;
    private void OnTriggerStay(Collider other)
    {
       
        if (isend) 
        {
            return;
        }

        if (other.tag=="Player") 
        {

            timer += Time.deltaTime;

            if (timer>=2F)
            {
                if (ISA) 
                {
                    Shuniupai.transform.localScale = Vector3.MoveTowards(Shuniupai.transform.localScale, new Vector3(origscale.x, 0, origscale.z), 0.8F * Time.deltaTime);
                    if (Shuniupai.transform.localScale== new Vector3(origscale.x, 0, origscale.z)) 
                    {
                        ISA = false;
                        ISB = true;
                    }
                }
                if (ISB) 
                {
                    Shuniupai.transform.localScale = Vector3.MoveTowards(Shuniupai.transform.localScale,origscale,0.07f*Time.deltaTime );
                    if (Shuniupai.transform.localScale == origscale)
                    {
                        isend = true;
                        timer = 0;
                        ISB = false;
                    }

                }




               
            }
        }
    }
    private void OnTriggerExit(Collider other)
    {
        
    }
}
