39 lines
888 B
C#
39 lines
888 B
C#
|
|
using UnityEngine;
|
|
|
|
public class PipeSpawnScript : MonoBehaviour
|
|
{
|
|
public GameObject Pipe;
|
|
public float SpawnRate = 2;
|
|
private float timer =0;
|
|
public float heightOfSet = 10;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
spawnpipe();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if ( timer < SpawnRate)
|
|
{
|
|
timer = timer + Time.deltaTime;
|
|
}
|
|
else
|
|
{
|
|
spawnpipe();
|
|
timer = 0;
|
|
}
|
|
}
|
|
|
|
void spawnpipe()
|
|
{
|
|
float lowestpoint = transform.position.y - heightOfSet;
|
|
float heighestpoint = transform.position.y + heightOfSet;
|
|
|
|
Instantiate(Pipe, new Vector3 (transform.position.x, Random.Range(lowestpoint, heighestpoint), 0), transform.rotation);
|
|
|
|
}
|
|
}
|