forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawner.cs
More file actions
42 lines (37 loc) · 1.4 KB
/
Copy pathSpawner.cs
File metadata and controls
42 lines (37 loc) · 1.4 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
30
31
32
33
34
35
36
37
38
39
40
41
42
using UnityEngine;
public class Spawner : MonoBehaviour
{
// The set of targets is fixed, so rather than
// retrieve the targets every frame, we'll cache
// their transforms in this field.
public static Transform[] TargetTransforms;
public GameObject SeekerPrefab;
public GameObject TargetPrefab;
public int NumSeekers;
public int NumTargets;
public Vector2 Bounds;
public void Start()
{
Random.InitState(123);
for (int i = 0; i < NumSeekers; i++)
{
GameObject go = GameObject.Instantiate(SeekerPrefab);
Seeker seeker = go.GetComponent<Seeker>();
Vector2 dir = Random.insideUnitCircle;
seeker.Direction = new Vector3(dir.x, 0, dir.y);
go.transform.localPosition = new Vector3(
Random.Range(0, Bounds.x), 0, Random.Range(0, Bounds.y));
}
TargetTransforms = new Transform[NumTargets];
for (int i = 0; i < NumTargets; i++)
{
GameObject go = GameObject.Instantiate(TargetPrefab);
Target target = go.GetComponent<Target>();
Vector2 dir = Random.insideUnitCircle;
target.Direction = new Vector3(dir.x, 0, dir.y);
TargetTransforms[i] = go.transform;
go.transform.localPosition = new Vector3(
Random.Range(0, Bounds.x), 0, Random.Range(0, Bounds.y));
}
}
}