Home Game Development unity – Why when setting the period to 0 after which again to 1 or any worth above 0 the fading shouldn’t be proceed?

unity – Why when setting the period to 0 after which again to 1 or any worth above 0 the fading shouldn’t be proceed?

0
unity – Why when setting the period to 0 after which again to 1 or any worth above 0 the fading shouldn’t be proceed?

[ad_1]

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class Fader : MonoBehaviour
{
    public GameObject objectToScale;
    public float period = 1f;
    public Vector3 minSize;
    public Vector3 maxSize;
    public bool scaleUp = false;
    public Coroutine scaleCoroutine;
    public bool isAutomatic = false;

    personal bool automated = true;

    personal void Start()
    {
        objectToScale.remodel.localScale = minSize;
    }

    personal void Update()
    {
        if (Input.GetKeyDown(KeyCode.G))
        {
            Fade();
        }

        if (isAutomatic && automated)
        {
            Fade();

            automated = false;
        }
    }

    personal IEnumerator ScaleOverTime(GameObject targetObj,
        Vector3 toScale, float period)
    {
        float counter = 0;
        Vector3 startScaleSize = targetObj.remodel.localScale;

        whereas (counter < period)
        {
            counter += Time.deltaTime;
            targetObj.remodel.localScale = Vector3.Lerp(startScaleSize, toScale, counter / period);

            yield return null;
        }

        automated = true;
    }

    personal void Fade()
    {
        scaleUp = !scaleUp;

        if (scaleCoroutine != null)
            CeaseCoroutine(scaleCoroutine);

        if (scaleUp)
        {
            scaleCoroutine = StartCoroutine(ScaleOverTime(objectToScale, maxSize, period));
        }

        else
        {
            scaleCoroutine = StartCoroutine(ScaleOverTime(objectToScale, minSize, period));
        }
    }
}

i can change the period to 0.1 or 1 or 5 or 10 but when i alter the period to 0 and the fading stopped then when i alter again the period to any worth above 0 the fading shouldn’t be proceed. i attempted it on the automated mode when isAutomatic is true. i can not work out why after setting to 0 and again to 1 the fading shouldn’t be proceed ?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here