This is a part of my script. The GameObjects don't spawn at the time I expect them to. I tried to change the time scale in relationship to the delay value (i. e. timescale = 1 & baseDelay = .1f to timescale = 10 & baseDelay = 1). This how ever works like a charm and I really don't know why. Is something wrong with my code? Has unity problems with the FixedUpdate and small floats?
Images:
using System; using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour {
internal int xCount = 5; //bricks in x per line
internal float spacing = .5f; //space between bricks and margin to edges
internal float baseDelay = .1f; //time that needs to pass until the next movement internal
float brickMovementPerStep = .05f; //movement distance per step
int currentLineNumber = 0; //index for current line
void FixedUpdate()
{
//accurate value of space which needs to pass
float dist = ((screenSize.x - (2 * spacing + ((xCount - 1) * spacing))) / xCount) * .667f + spacing;
float stepsPerSecond = 1 / baseDelay; //how many steps are there per second?
float movementPerSecond = stepsPerSecond * brickMovementPerStep; //how far will a line have moved?
float requiredTime = dist / movementPerSecond; //how long will a line need to travel until the next one can be spawned?
timeSinceLastSpawn += Time.deltaTime;
if(timeSinceLastSpawn >= requiredTime)
{
timeSinceLastSpawn = 0; //reset time
currentLineNumber++;
SpawnAndStartLevel(); //this instantiates and moves the line, it is moved continously
}
}