[Solved] Making an object generator that generates according to time.

I tried making an object generator that generates objects according to time, but it’s not working the way I want it to. I want the generator to generate only one object during certain time. Currently, my generator is working, just that it generates a lot of object continuously. I have a generator manager in which I will pass in float values and store them into an array and I will check them against the current time, if both values equates, the generator will generate one object. The result that I am getting now is when the value stored in the first array slot is equivalent to the value of the current time, nothing happens. When the value stored in the second array slot is equivalent to the value of the current time, the generator generates a lot of objects for a brief period of time. Can anyone kindly teach me what should I do to get the generator to generate one object at a time? Help rendered will be greatly appreciated!

Generator.cs:

void Update ()
{
    StateChange();
}
    
private void StateChange()
{
    Camera mainCamera = Camera.main;
    GeneratorManager genManager = mainCamera.GetComponent<GeneratorManager>();
    		
    if ( currentState == GeneratorState.active )
    {
    	Spawn();
    			
    }
    		
    else if ( currentState == GeneratorState.notActive )
    {
    }
   }
    	
private void Spawn()
{
   // Instantiate the prefab
    Transform newPrefab = ( Transform ) Instantiate( thePrefab,
   	new Vector3( this.transform.position.x, this.transform.position.y, this.transform.position.z ),
    	Quaternion.identity);
}

GeneratorManager.cs:

void Update ()
{
    Debug.Log ( Mathf.RoundToInt( Time.timeSinceLevelLoad ) );
    Generator gen = GameObject.Find("Generator").GetComponent<Generator>();
		
for ( int i = 0; i < timeTable.Length; i ++ )
{
	// If any of the component values inside the timeTable is the same
	// as the current time in game
	if ( timeTable *== Mathf.RoundToInt( Time.timeSinceLevelLoad ) )*
  • {*

  •  isSpawn = true;*
    
  •  Debug.Log ("Hey");*
    
  • }*

  • else*

  • {*

  •  isSpawn = false;*
    
  • }*
    }

if ( isSpawn )
{

  • gen.SetIsActivated( true );*

  • theCounter ++;*

  • if ( theCounter >= timeTable.Length )*

  • {*

  •  theCounter = 0;*
    
  • }*
    }

else
{

  • gen.SetIsActivated( false );*
    }
    }

Generator.cs:

void Update ()
{
if ( Time.timeSinceLevelLoad >= timeTable[currentTimeTableIndex] )
{
Spawn();

			if ( currentTimeTableIndex <= timeTable.Length - 1 )
			{
				currentTimeTableIndex ++;
			}
		}
	}

	private void Spawn()
	{
		// Instantiate the prefab
		Transform newPrefab = ( Transform ) Instantiate( thePrefab,
			new Vector3( this.transform.position.x, this.transform.position.y, this.transform.position.z ),
			Quaternion.identity);
	}

This is the working solution.