Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PipeSpawnScript : MonoBehaviour
- {
- public GameObject pipe;
- public float spawnRate = 2;
- private float timer = 0;
- private 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;
- }
- else
- {
- spawnPipe();
- timer = 0;
- }
- }
- 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), 0), transform.rotation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement