Change Seconds -Spawner (Script)

Help, support and information for our Pro Pooling Unity Asset
Post Reply
martiallaw
Posts: 4
Joined: Mon May 21, 2018 8:40 am

Change Seconds -Spawner (Script)

Post by martiallaw » Thu Jun 21, 2018 3:58 pm

Hello,
I need to change the seconds because I'm using a powerup via script.
propooling.gif
propooling.gif (26.88 KiB) Viewed 7745 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()
		
		Destroy(this.gameObject);
        
		}
		}
	void Awake(){
		sp=GameObject.Find("COCHEpool").GetComponent<Spawner>();
		}
		
		
    }
	

Code: Select all

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

regards

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Change Seconds -Spawner (Script)

Post by mahewitt » Mon Jun 25, 2018 8:44 am

Hi,

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.

Regards,
Mark

martiallaw
Posts: 4
Joined: Mon May 21, 2018 8:40 am

Re: Change Seconds -Spawner (Script)

Post by martiallaw » Wed Jun 27, 2018 7:00 pm

Hi,
How could I implement it in my current code?
Regards

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Change Seconds -Spawner (Script)

Post by mahewitt » Thu Jun 28, 2018 9:08 pm

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;

martiallaw
Posts: 4
Joined: Mon May 21, 2018 8:40 am

Re: Change Seconds -Spawner (Script)

Post by martiallaw » Fri Aug 03, 2018 7:42 am

Hi,
It works for me like this:
sp.SpawnOverTime.SpawnInterval = 0.5f;
sp.SpawnOverTime.UpdateCachedValues();

rewards

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Change Seconds -Spawner (Script)

Post by mahewitt » Fri Aug 03, 2018 12:40 pm

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.

Mark

Post Reply