Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
1
Indexable
Never
using UnityEngine;

namespace BuildSite.State {

    public class Constructing : StateMachine.IState
    {

        private BuildSite.Handler buildSite;
        private float constructTimer;

        public Constructing(BuildSite.Handler _buildSite) {
            buildSite = _buildSite;
        }

        public void Enter() {
            buildSite.SetIsConstructing(true);
            buildSite.InvokeOnBeginConstructing();

            constructTimer = buildSite.GetConstructTimer();
        }

        public void Update() {
            constructTimer -= Tick.instance.GetTimerMax();
            if (FinishedConstructing()) {
                SpawnBuilding();

                buildSite.ClearCurrentBuildingPf();
                buildSite.SetIsConstructing(false);
                buildSite.InvokeOnEndConstructing();
            }
        }

        public void Exit() {
            
        }

        public bool FinishedConstructing() {
            return constructTimer <= 0f;
        }

        private void SpawnBuilding() {
            Transform pfTransform = buildSite.GetCurrentBuildingPf();
            Vector3 position = buildSite.transform.position;
            MonoBehaviour.Instantiate(pfTransform, position, Quaternion.identity);
        }
        
    }
}