C
C
coutBohdan2020-04-03 21:31:58
Character encoding
coutBohdan, 2020-04-03 21:31:58

Why is the code not working. Is it because of FixUpdate and Void Start??

How to make this delay????? I have already tried many ways.
StartCoroutine should not start at the beginning of the scene??
using System.Collections;
using UnityEngine;

public class SpawnBox : MonoBehavior
{
public float miliSecond;
public float second;
public GameObject bomb;
public void FixedUpdate()
{
miliSecond += 0.02f;
if (miliSecond >= 1f)
{
second++;
miSecond = 0f;

}
}
void Start()

{
if (second >= 1f)
{
StartCoroutine(Spawn());
}
}
IEnumerator Spawn()
{
while (!Player.lose)
{
Instantiate(bomb, new Vector2(Random.Range(-2.5f, 2.5f), 5.9f), Quaternion.identity);
yield return new WaitForSeconds(2f);

}

}

}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
andrash_, 2019-09-26
@andrashsh

Save the file in UTF 8 encoding without BOM. Then pour

A
Adamos, 2019-09-26
@Adamos

Set up the server. He gives you this page with the title
Content-Type: text/html; charset=windows-1251

G
GavriKos, 2020-04-03
@GavriKos

The code in Start is executed at the start of the script (roughly speaking) and earlier than FixedUpdate. At this point, second will still be equal to 0. And no coroutine will be executed.

C
coutBohdan, 2020-04-03
@coutBohdan

StartCoroutine should not start at the beginning of the scene?? - here without question marks.

X
xmoonlight, 2020-04-03
@xmoonlight

see here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question