Advertisement
gandalfbialy

Untitled

Jun 14th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class FloorController : MonoBehaviour
  4. {
  5.     public GameObject floorTiles1, floorTiles2;
  6.     public GameObject[] floorTiles;
  7.  
  8.     private void FixedUpdate()
  9.     {
  10.         if (!GameManager.instance.inGame)
  11.         {
  12.             return;
  13.         }
  14.  
  15.         floorTiles1.transform.position -= new Vector3(GameManager.instance.worldScrollingSpeed, 0f, 0f);
  16.         floorTiles2.transform.position -= new Vector3(GameManager.instance.worldScrollingSpeed, 0f, 0f);
  17.  
  18.         if (floorTiles2.transform.position.x < 0f)
  19.         {
  20.             //floorTiles1.transform.position += new Vector3(36f, 0f, 0f);
  21.             int randomIndex = Random.Range(0, floorTiles.Length);
  22.             var newFloorTile = Instantiate(floorTiles[randomIndex], floorTiles2.transform.position + new Vector3(18f, 0f, 0f), Quaternion.identity);
  23.  
  24.             Destroy(floorTiles1);
  25.  
  26.             //var temp = floorTiles1;
  27.             floorTiles1 = floorTiles2;
  28.             floorTiles2 = newFloorTile;
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement