Home > OS >  How do I get the boss to attack again 10 seconds after the last attack?
How do I get the boss to attack again 10 seconds after the last attack?

Time:12-15

I'm new in unity and all the programing language so I don't know How do I get the bossPattern to starts again after 10 seconds when the boss pattern is over. could you can give how to make that?

I want to make sure that the pattern starts again after 10 seconds when the boss pattern is over.

CodePudding user response:

You can implement a simple timer and after 10 seconds start your "StartBossPattern" and reset your timer:

float timer = 0f;

void Update()
{
    timer -= Time.deltaTime;

    if (timer <= 0f)
    {
        //Start Boss Pattern

        timer = 10f;
    }
}

But this is only one way to do it.

CodePudding user response:

method 1:

float lastAttackTime=0;
float attackTimeGap=10;

void update()
{
if (Time.time-lastAttackTime>attackTimeGap)
{
//attack
lastAttackTime = Time.time;
}
}

method 2:

void update()
{
startCoroutine(Attack());
}
IEnumerator Attack()
{
//attack
yeild return new WaitForSeconds(10);
startCoroutine(Attack());
}
  • Related