Rabbit.cs 1.89 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public enum RabbitState
{
    None,
    Pop,
    Idle,
    Die,
    Exit
}

public class Rabbit : MonoBehaviour
{
    private Animator m_animator;

    public RabbitState state = RabbitState.None;
    public GameObject body;

    private float m_resetTime = 0f;
    private float m_exitTime = 0f;

    private void Awake()
    {
        m_animator = GetComponent<Animator>();
        SetResetTime();
    }


    private void SetResetTime()
    {
        m_resetTime = Random.Range(1.5f, 6f);
    }


    public void None()
    {
        state = RabbitState.None;
        body.SetActive(false);
        m_animator.SetBool("dying", false);
        m_animator.SetBool("exiting", false);
        SetResetTime();
    }

    public void Pop()
    {
        state = RabbitState.Pop;
        body.SetActive(true);
        m_animator.SetBool("poping", true);
    }

    public void Idle()
    {
        state = RabbitState.Idle;
        m_animator.SetBool("poping", false);
    }

    public void Die()
    {
        state = RabbitState.Die;
        m_animator.SetBool("dying", true);
    }

    public void Exit()
    {
        state = RabbitState.Exit;
        m_exitTime = 0f;
        m_animator.SetBool("exiting", true);
    }


    private void Update()
    {
        if (MiniGameManager.gameState == GameState.Play)
        {
            float dt = Time.deltaTime;

            if (state == RabbitState.None)
            {
                body.SetActive(false);
                m_resetTime -= dt;

                if (m_resetTime <= 0)
                    Pop();

                return;
            }
            else if (state == RabbitState.Idle)
            {
                m_exitTime += dt;
                if (m_exitTime >= 2)
                    Exit();

                return;
            }
        }
        else
            return;
    }
}