Friday, August 26, 2022
HomeGame Developmentunity - Why when setting the period to 0 after which again...

unity – Why when setting the period to 0 after which again to 1 or any worth above 0 the fading is just not proceed?


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;

    non-public bool computerized = true;

    non-public void Begin()
    {
        objectToScale.rework.localScale = minSize;
    }

    non-public void Replace()
    {
        if (Enter.GetKeyDown(KeyCode.G))
        {
            Fade();
        }

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

            computerized = false;
        }
    }

    non-public IEnumerator ScaleOverTime(GameObject targetObj,
        Vector3 toScale, float period)
    {
        float counter = 0;
        Vector3 startScaleSize = targetObj.rework.localScale;

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

            yield return null;
        }

        computerized = true;
    }

    non-public void Fade()
    {
        scaleUp = !scaleUp;

        if (scaleCoroutine != null)
            StopCoroutine(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 is just not proceed. i attempted it on the automated mode when isAutomatic is true. i am unable to work out why after setting to 0 and again to 1 the fading is just not proceed ?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments