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
43
44
45
using System;
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour
{
public GameObject BasicEnemy;
public GameObject StaticEnemy;
public GameObject Toluen;
private float _timer;
private System.Random _rand;
private float _rightBorder;
void Start ()
{
_timer = 0f;
_rand = new System.Random();
}
void Update ()
{
_timer += Time.deltaTime;
_rightBorder = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0)).x + 2;
if (_timer >= Math.Max((2 / (Time.time / 10)), .5f))
{
Spawn();
_timer = 0f;
}
}
private void Spawn()
{
var r = _rand.Next(100);
if (r < 20)
Instantiate(StaticEnemy, new Vector3(_rightBorder, _rand.Next(1, 9), 0), Quaternion.identity);
else if (r < 45)
Instantiate(Toluen, new Vector3(_rightBorder, _rand.Next(1, 9), 0), Quaternion.identity);
r = _rand.Next(100);
if (r < 50)
Instantiate(BasicEnemy, new Vector3(_rightBorder, _rand.Next(1, 9), 0), Quaternion.identity);
}
}