-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tank.cs
75 lines (64 loc) · 2.67 KB
/
Tank.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
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
66
67
68
69
70
71
72
73
74
75
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Tank : MonoBehaviour
{
[SerializeField] private float heightBaseTank;
[SerializeField] public float waterHeight;
[SerializeField] public float maxWaterHeight;
[SerializeField] public float timeEmpty;
[SerializeField] private GameObject prefabHole;
public List<GameObject> holes;
public GameObject waterLevel;
public GameObject waterTop;
public Vector2 size;
public float timerNotFull = 0;
public bool shouldFillTank;
// Start is called before the first frame update
void Start()
{
waterLevel.transform.localScale = new Vector3(waterLevel.transform.localScale.x, size.y, waterLevel.transform.localScale.z);
}
// Update is called once per frame
void FixedUpdate()
{
if (holes.Count > 1)
{
Destroy(holes[0]);
holes.RemoveAt(0);
}
if (shouldFillTank)
{
timerNotFull = 0;
waterHeight = maxWaterHeight;
shouldFillTank = false;
}
timerNotFull += Time.fixedDeltaTime;
waterLevel.transform.localScale = new Vector3(waterLevel.transform.localScale.x, waterHeight, waterLevel.transform.localScale.z);
waterTop.transform.localPosition = new Vector3(waterTop.transform.localPosition.x, waterLevel.transform.localScale.y - waterTop.transform.localScale.y, waterTop.transform.localPosition.z);
}
public void AddHole(Hole holePreview)
{
Vector3 pos = holePreview.transform.position;
GameObject hole = Instantiate(prefabHole);
hole.transform.position = new Vector3(waterLevel.transform.position.x + waterLevel.transform.localScale.x * 0.5f, pos.y, pos.z);
holes.Add(hole);
Hole holeComp = hole.GetComponent<Hole>();
holeComp.height = pos.y - heightBaseTank;
holeComp.transform.localScale = holePreview.transform.localScale;
holeComp.particles = hole.GetComponentInChildren<ParticleSystem>();
Vector3 maxScale = holeComp.particles.gameObject.transform.localScale;
float scale = Hole.Remap(holePreview.diameter, 1, 50, 0.15f, maxScale.x);
holeComp.particles.gameObject.transform.localScale = new Vector3(scale , scale, scale);
holeComp.SetTank(this);
}
public Hole CreateHole()
{
GameObject hole = Instantiate(prefabHole);
hole.transform.position = new Vector3(waterLevel.transform.position.x + waterLevel.transform.localScale.x * 0.5f, 0, 0);
Hole holeComp = hole.GetComponent<Hole>();
holeComp.isPreview = true;
return holeComp;
}
}