mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2024-12-18 21:44:51 +01:00
39 lines
829 B
C#
39 lines
829 B
C#
|
using UnityEngine;
|
||
|
|
||
|
public class PipeSpawnScript : MonoBehaviour
|
||
|
{
|
||
|
public GameObject pipe;
|
||
|
public BirdScript bird;
|
||
|
public float spawnRate = 1;
|
||
|
private float timer = 0;
|
||
|
public float heightOffset = 10;
|
||
|
|
||
|
public void Start()
|
||
|
{
|
||
|
SpawnPipe();
|
||
|
}
|
||
|
|
||
|
public void Update()
|
||
|
{
|
||
|
if (!bird.isAlive)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
if (timer < spawnRate)
|
||
|
{
|
||
|
timer += Time.deltaTime;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SpawnPipe();
|
||
|
timer = 0;
|
||
|
}
|
||
|
|
||
|
public void SpawnPipe()
|
||
|
{
|
||
|
float lowestPoint = transform.position.y - heightOffset;
|
||
|
float highestPoint = transform.position.y + heightOffset;
|
||
|
Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint)), transform.rotation);
|
||
|
}
|
||
|
}
|