-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointSprawner.cs
36 lines (31 loc) · 1.07 KB
/
PointSprawner.cs
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
using UnityEngine;
public class PointSprawner : MonoBehaviour
{
public GameObject PointPrefab;
public Transform player;
private int FixedY = 1; // fix the upcoming obstacle in y plane
private float timeToSprawn = 2f;
private float timeBetween = 0.5f;
void Update()
{
if (Time.time >= timeToSprawn)
{
sprawnPoint();
timeToSprawn = Time.time + timeBetween;
}
}
void sprawnPoint()
{
if (player.position.z <= 440)
{
// randomnize the emergence place of the goal
int RandomX = Random.Range(-7, 7); // position in x
int aheadValue = Random.Range(38, 45); // the goal should be ahead of the player
int RandomZ = (int)(player.position.z + aheadValue); // z position ahead of player
Vector3 pos = new Vector3(RandomX, FixedY, RandomZ); // position
GameObject point = Instantiate(PointPrefab); // initiate obstacle
point.transform.position = pos; //goal position
}
}
}