Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Spawner : MonoBehaviour
- {
- public GameObject objectToSpawn;
- public float delay = 2;
- public float delayAtStart = 3;
- public float timer = 0;
- public float randomHorizontalSpawnTreshold = 1;
- public float levelMultiplier = 1;
- float level;
- public bool spawning = false;
- Data data;
- float startDelay;
- // Use this for initialization
- void Awake()
- {
- startDelay = delay;
- }
- void Start()
- {
- timer = 0;
- }
- void OnEnable()
- {
- delay = startDelay;
- data = FindObjectOfType<Data>();
- level = data.level;
- delay = delay - (delay * level * levelMultiplier);
- }
- // Update is called once per frame
- void Update()
- {
- timer += Time.fixedDeltaTime;
- if (timer >= delayAtStart && !spawning)
- {
- spawning = true;
- timer = 0;
- }
- if (timer >= delay && spawning)
- {
- Instantiate(objectToSpawn, new Vector3(Random.Range(-randomHorizontalSpawnTreshold, randomHorizontalSpawnTreshold), transform.position.y, transform.position.z), Quaternion.identity);
- timer = 0;
- }
- }
- public void ResetSpawner()
- {
- timer = 0;
- spawning = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement