I have a question about Time.deltaTime.

Posted: 09 Nov 2022 03:22
by booksuny

Hello. I ran into a problem while working on a code that was increasing the number of SPs.

I made the code.

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Naninovel;

public class SP_Bar : MonoBehaviour {

private void Update()    
{
    var variableManager = Engine.GetService<ICustomVariableManager>();

    variableManager.TryGetVariableValue<float>("enemy_SP", out var enemy_SP);

    variableManager.TryGetVariableValue<bool>("SP_stop", out var SP_stop);

    RectTransform rectTran = gameObject.GetComponent<RectTransform>();        
    rectTran.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 1000/100*enemy_SP);

    if (SP_stop==true){
        enemy_SP += 0.3f * Time.deltaTime;
        if (enemy_SP >= 100f){
            enemy_SP = 100f;
        }
    }

    variableManager.TrySetVariableValue("enemy_SP", enemy_SP);      

}
}

Then, I found that the SP increases when using skip, but the SP does not increase when the skip is turned off.

I think Time.delta Time is the problem.

Is there a way to solve this problem using Time.deltaTime?


Re: I have a question about Time.deltaTime.

Posted: 09 Nov 2022 07:20
by booksuny

Resolved with 'Time.unscaledDeltaTime'. For those who have the same problem, please refer to it.