I’m following GMTK Unity for beginners Flappy Bird tutorial and I’m at the part where you get pipes to spawn at random y levels I put in all the code but there still only spawning at the same y level, any help would be appreciated, thanks
PipeSpawnScript code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeSpawnScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
private float timer = 0;
public float heightOffset = 10;
// Start is called before the first frame update
void Start()
{
spawnPipe();
}
// Update is called once per frame
void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}f
else
{
spawnPipe();
timer = 0;
}
}
void spawnPipe()
{
float lowestPoint = transform.position.y - heightOffset;
float heightestPoint = transform.position.y + heightOffset;
Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, heightestPoint), 0), transform.rotation);
}
}