Skip to content
Snippets Groups Projects
Commit 5cef778f authored by gawen.ackerman's avatar gawen.ackerman :robot:
Browse files

UPDATE : Allowing to select a height range for spawning

parent 614a7d79
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -584,6 +584,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
gearPrefab: {fileID: 7134382842353009887, guid: bfde8172a222719488e32620f57841ca, type: 3}
spawningHeightRange: 0.7
--- !u!1 &1099179302
GameObject:
m_ObjectHideFlags: 0
......
......@@ -6,6 +6,8 @@ public class CollectibleGenerator : MonoBehaviour
{
public GameObject gearPrefab;
[Range(0, 1f)]
public float spawningHeightRange = .5f;
public void SpawnCollectibles()
{
......@@ -26,7 +28,13 @@ public class CollectibleGenerator : MonoBehaviour
if (spawnSlots.Count > 0)
{
int randomIndex = Random.Range(0, spawnSlots.Count);
Instantiate(gearPrefab, spawnSlots[randomIndex].position, Quaternion.identity);
Transform chosenSlot = spawnSlots[randomIndex];
float randomHeight = Random.Range(0, spawningHeightRange);
Vector3 spawnPosition = new Vector3(chosenSlot.position.x, chosenSlot.position.y + randomHeight, chosenSlot.position.z);
GameObject collectible = Instantiate(gearPrefab, spawnPosition, gearPrefab.transform.rotation);
collectible.transform.SetParent(chosenSlot, true);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment