PracProg/Assets/Scripts/ColumnSpawner.cs

50 lines
996 B
C#
Raw Permalink Normal View History

2021-02-04 19:49:39 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColumnSpawner : MonoBehaviour
{
public GameObject column;
public float maxTime;
float timer;
public float maxY;
public float minY;
float randY;
// Start is called before the first frame update
void Start()
{
//InstantiateColumn();
}
// Update is called once per frame
void Update()
{
if(GameManager.gameOver == false &&
GameManager.gameHasStarted == true)
{
timer += Time.deltaTime;
if (timer >= maxTime)
{
InstantiateColumn();
timer = 0;
}
}
}
public void InstantiateColumn()
{
randY = Random.Range(minY, maxY);
GameObject newColumn = Instantiate(column);
newColumn.transform.position = new Vector2(
transform.position.x,
randY);
}
}