Hello, I have a question about Time.deltatime.

What I want to make is..
'for example, Ezreal, the character is in the game named ‘League of Legends’
and this character has skill that
if this character hit the special arrow(skill), ezreal’s all the skill cooltime reduce 1.5seconds.

so I tried with time.deltatime

but it works very wrong.

first my code is

Script A

void FixedUpdate()
{

    UltMode();
    
    if (Input.GetButtonDown("UltMode") && currentUltgauge == maxUltgauge)
    {
        SetPlayerState(PlayerState.Ultimate);            
    }       
}

public void UltMode()
{
if (isCharge == true)
{
currentUltgauge += 1 * Time.deltaTime;
Debug.Log(currentUltgauge);
if (currentUltgauge == maxUltgauge)
{
isCharge = false;
Debug.Log(“your ult is Ready”);
return;
}
}
}

this code works very well, but if i add function that add value to’ currentUltgauge’ while time.deltaTime works, the log shows infinity.

here’s what i did. Bold letters means, I add some code to perform a function.

ScriptA

void FixedUpdate()
{

    UltMode(**0**);
    
    if (Input.GetButtonDown("UltMode") && currentUltgauge == maxUltgauge)
    {
        SetPlayerState(PlayerState.Ultimate);            
    }       
}

public void UltMode(float gauge)
{

    if (isCharge == true)
    {            
        currentUltgauge += 1 * Time.deltaTime;            
        **currentUltgauge += gauge;**
        Debug.Log(currentUltgauge);
        if (currentUltgauge == maxUltgauge)
        {
            isCharge = false;
            Debug.Log("your ult is Ready");
            return;
        }
    }
} 

Script B

void OnTriggerEnter2D(Collider2D col)
{
if(col.tag == “EnemyShipTag”)
{
col.gameObject.SendMessage(“UltMode”, 10f, SendMessageOptions.DontRequireReceiver);
Destroy(gameObject);
}
}


well.. I tried like this.. but not really works.
may be i tried wrong way(pool programming skill, started learning programming a month ago)

can somebody help me to solve this problem?

2 Answers

2

What is actually your question here? Are you wondering how Time.deltatime works, or how to time delays and such like with a coroutine?

Here’s the Unity manual page on Time.delta time: Unity - Scripting API: Time.deltaTime

If you’re looking for delays and timing things, I’d look into coroutines: Unity - Manual: Coroutines

Coroutines are a bit tricky at first, but really simple once you get the hang of them. Basically, you use yield return new WaitForSeconds(.1f); to create a delay, but make sure you do that in the IEnumerator interface.

I tried the second one you answered, Code works, but I still don't know how coroutine works :( I think, I need to spend a time to master coroutine :) Thank you for answering, it really helped me :)

You have isTrigger checked? I'm running out of ideas here and sense this is something basic that's been missed.

Still nothing /:

Umm… First of all, Sorry for my explanation with poor english(not native).

my question is actually…

here’s example

maximum is 10, and we start from 0, every seconds will add 1(Time.deltaTime). but this is my actual question.

0(start) + 1 (Time.deltaTime) + 1 +1 +3(Trigger? or SendMessage? how can I make this?) +1+1+1+1 = Maximum

add some value while Time.deltaTime works.

So I tried the Second Code(ScriptA+B at the First Question), but it didn’t work as the example.

how can i do to make that example?

Yup, on the tiles the isTrigger is checked. I have a rigidbody on the player that is checked to Kinematic.