Page 1 of 1

Change Seconds -Spawner (Script)

Posted: Thu Jun 21, 2018 3:58 pm
by martiallaw
I need to change the seconds because I'm using a powerup via script.
propooling.gif (26.88 KiB) Viewed 32241 times
This script is from another power up that stopped the spawer with a coroutine

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ProPooling;
using ProPooling.Components;
// using MEC;
// using TMPro;

public class PUcocheMAS : MonoBehaviour {

Spawner sp;

	void OnTriggerEnter2D(Collider2D powerCol){
		if (powerCol.gameObject.tag == "Player") {  
		sp.PararCoche(); //StartSpawning()  //StopSpawning()
	void Awake(){

Code: Select all

public void PararCoche(){
			Timing.RunCoroutine( PararCocheP(),"coche");
        IEnumerator<float> PararCocheP ()
           // PUB.CocheMenosVer(true);
           // PUB.CocheMenosVerTXT(true);
            yield return Timing.WaitForSeconds( 1.5f );
            yield return Timing.WaitForSeconds( 8.5f );
           // PUB.CocheMenosVer(false);
how can I change the seconds with a coroutine and then go back to the original seconds


Re: Change Seconds -Spawner (Script)

Posted: Mon Jun 25, 2018 8:44 am
by mahewitt

If you have a reference to the Spawner component then you will find several methods including for starting / stopping spawning etc..

From the Spawner reference you can access many of the properties shown in the inspector under the SpawnOverTime property. One of these is SpawnTime that holds the value you mention. You can modify this also whilst the spawner is running.

Let me know if that achieves what you are after.


Re: Change Seconds -Spawner (Script)

Posted: Wed Jun 27, 2018 7:00 pm
by martiallaw
How could I implement it in my current code?

Re: Change Seconds -Spawner (Script)

Posted: Thu Jun 28, 2018 9:08 pm
by mahewitt
Hi. Not 100% sure that I quite got the whole code logic, but given your reference to sp you should just be able to put something like the below when you need to change the seconds:

sp.SpawnOverTime.SpawnTime = 0.5f;

Re: Change Seconds -Spawner (Script)

Posted: Fri Aug 03, 2018 7:42 am
by martiallaw
It works for me like this:
sp.SpawnOverTime.SpawnInterval = 0.5f;


Re: Change Seconds -Spawner (Script)

Posted: Fri Aug 03, 2018 12:40 pm
by mahewitt
Glad that you found a solution. I had forgotten about the CachedValues part - I will update in a future version so that is triggered automatically when you update a value - although it won't harm if you have code that calls it like below.