Advertisement
johnnygoodguy2000

PipeSpawnScript

Mar 17th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PipeSpawnScript : MonoBehaviour
  6. {
  7.     public GameObject pipe;
  8.     public float spawnRate = 2;
  9.     private float timer = 0;
  10.     private float heightOffset = 10;
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         spawnPipe();
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         if (timer < spawnRate)
  21.         {
  22.             timer = timer + Time.deltaTime;
  23.         }
  24.         else
  25.         {
  26.             spawnPipe();
  27.             timer = 0;
  28.         }
  29.        
  30.     }
  31.     void spawnPipe()
  32.     {
  33.         float lowestPoint = transform.position.y - heightOffset;
  34.         float highestPoint = transform.position.y + heightOffset;
  35.         Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0), transform.rotation);
  36.  
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement