-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTankNewSpawn.cs
More file actions
65 lines (54 loc) · 1.47 KB
/
Copy pathTankNewSpawn.cs
File metadata and controls
65 lines (54 loc) · 1.47 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using UnityEngine;
public class TankNewSpawn : MonoBehaviour
{
public GameObject enemyTank;
public float delay1 = 4f;
public GameObject friendlyTank;
public float delay2 = 8f;
public float spawnRange = 30f;
private float timeStart1;
private float timeStart2;
void Start()
{
timeStart1 = 0f;
timeStart2 = 0f;
}
void Update()
{
timeStart1 += Time.deltaTime;
timeStart2 += Time.deltaTime;
if (timeStart1 > delay1)
{
SpawnTank(true);
timeStart1 -= delay1;
}
if (timeStart2 > delay2)
{
SpawnTank(false);
timeStart2 -= delay2;
}
}
public void SpawnTank(bool isEnemy)
{
Vector3 spawnPosition = new Vector3(
Random.Range(-spawnRange, spawnRange) + transform.position.x,
transform.position.y,
30f + transform.position.z
);
Quaternion spawnRotation = Quaternion.AngleAxis(180f, Vector3.up);
GameObject tankToSpawn = isEnemy ? enemyTank : friendlyTank;
Instantiate(tankToSpawn, spawnPosition, spawnRotation, transform);
}
public void DestroyAllTanks()
{
foreach (Transform child in transform)
{
if (child.CompareTag("EnemyAI") || child.CompareTag("Friendly"))
{
Destroy(child.gameObject);
}
}
timeStart1 = 0f;
timeStart2 = 0f;
}
}