How do I change an instantiation interval using a slider?
The past few days I have spent trying hard to change an instantiation interval using a slider. Or said differently: I want to change the tempo with which GameObjects are being spawned using a slider. However I do net get it to work. Are you able to help me out?! Thank you very much in advance :)
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour
{
public GameObject man;
public float InstantiationTimer = 10f;
void Start ()
{
}
void Update () {
CreatePrefab();
}
void CreatePrefab()
{
InstantiationTimer -= Time.deltaTime;
if (InstantiationTimer <= 0) {
Instantiate (man, transform.position, Quaternion.identity);
InstantiationTimer = 10f;
foreach(ParticleSystem p in GetComponentsInChildren<ParticleSystem>())
{
p.Play();
}
}
}
public void AdjustSpeed(float newSpeed) {
InstantiationTimer = newSpeed;
}
}
Comment
Your answer
Follow this Question
Related Questions
Spawn rate not matching the values 0 Answers
How do I take out a UI Slider's value? 0 Answers
lerp a float value of keyup 2 Answers
Slider with filter / search engine -1 Answers
Slider value help 0 Answers