-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphereSpawn
More file actions
29 lines (25 loc) · 1.15 KB
/
SphereSpawn
File metadata and controls
29 lines (25 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SphereSpawn : MonoBehaviour {
public float maxDist = 10;
public int sphereCount = 5;
public float minRadius = 0;
public float maxRadius = 5;
public GameObject sourceSphere;
//initializes the game by creating a set number of randomly sized and located spheres around the player's location
void Start() {
for (int i = 0; i < sphereCount; i++) {
Transform newTransform = GenRandTransform();
Instantiate(sourceSphere, newTransform.position, Quaternion.identity);
}
}
//this function returns a location and a radius within specified parameters, for use with spawning spheres
Transform GenRandTransform() {
Transform newTransform = sourceSphere.transform;
newTransform.position = new Vector3(maxDist * (Random.value * 2 - 1), maxDist * (Random.value * 2 - 1), maxDist * (Random.value * 2 - 1));
float randRadius = ((maxRadius-minRadius) * Random.value) + minRadius;
newTransform.localScale = new Vector3(randRadius, randRadius, randRadius);
return newTransform;
}
}