This commit is contained in:
haitem
2022-01-30 12:16:37 +01:00
13 changed files with 805 additions and 20 deletions

View File

@@ -5,10 +5,12 @@ using UnityEngine;
public class BGRotation : MonoBehaviour
{
private Vector3 rotation;
private ProceduralGeneration bgParrentScript;
private void Start()
{
rotation = new Vector3(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)) * 0.009f;
bgParrentScript = GameObject.Find("Level").GetComponent<ProceduralGeneration>();
}
void FixedUpdate()
@@ -20,7 +22,9 @@ public class BGRotation : MonoBehaviour
{
if (other.tag == "platform")
{
this.bgParrentScript.backgroundLevelBlocks.Remove(this.gameObject);
Destroy(this.gameObject);
}
}
}

View File

@@ -15,7 +15,7 @@ public class ProceduralGeneration : MonoBehaviour
public List<GameObject> backgroundBlocks = new List<GameObject>();
public List<GameObject> backgroundLevelBlocks = new List<GameObject>();
private float maximumDistanceOfPlatformFromPlayerBg = 600.0f;
public GameObject bgParrent = null;
private GameObject bgParrent = null;
public GameObject player = null;
public GameObject lastBlock;
@@ -103,12 +103,21 @@ public class ProceduralGeneration : MonoBehaviour
levelParrent = this.gameObject;
lastBlockPrefab = this.gameObject.transform.GetChild(0).gameObject;
lastBlock = this.gameObject.transform.GetChild(0).gameObject;
if (bgParrent == null)
{
bgParrent = GameObject.Find("Background");
}
this.spawnedLevelBlocks.Add(lastBlock);
}
// Update is called once per frame
void Update()
{
// if (playerControlsSript.isFalling)
// {
// return;
// }
Vector3 playerPosition = this.player.transform.position;
PlayerController playerControlsSript = this.player.GetComponent<PlayerController>();
@@ -120,11 +129,6 @@ public class ProceduralGeneration : MonoBehaviour
}
}
if (playerControlsSript.isFalling)
{
return;
}
for (var i = 0; i < this.backgroundLevelBlocks.Count; i++)
{
float distance = Vector3.Distance(this.backgroundLevelBlocks[i].transform.position, playerPosition);
@@ -158,7 +162,10 @@ public class ProceduralGeneration : MonoBehaviour
int blockToSpawn = Random.Range(0, (levelBlocks.Count + 1));
if (blockToSpawn > 31 && (blockToSpawn < levelBlocks.Count) && levelBlocks[blockToSpawn].name == lastBlockPrefab.name)
if (
(blockToSpawn > -1 && (blockToSpawn < levelBlocks.Count)) &&
(levelBlocks[blockToSpawn].name == lastBlockPrefab.name)
)
{
Debug.Log("Same Block");
if (blockToSpawn > levelBlocks.Count || blockToSpawn < 0)