-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColliderMovement.cs
117 lines (100 loc) · 3.08 KB
/
ColliderMovement.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColliderMovement : MonoBehaviour {
private BoxCollider2D movingBC2D;
private Vector2 initialSize;
private bool timeToResetSize = false;
private float counterToReset = 50f;
public ParticleSystem toxicSpew;
//Coroutine to keep the particle active after the player leaves the damage zone of the barrel
private IEnumerator particleKeep;
private float counterTillDisable = 5f;
private bool triggerDisableCounter = false;
// Use this for initialization
void Start () {
movingBC2D = GetComponent<BoxCollider2D>();
//reduction = new Vector2(movingBC2D.size.x, movingBC2D.size.y - 1f);
//sinkCoroutine = sink();
initialSize = movingBC2D.size;
particleKeep = WaitForParticle(10);
toxicSpew.Stop();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.name == "Player")
{
collision.transform.SetParent(gameObject.transform);
ReduceColliderSize();
timeToResetSize = false;
//toxicSpew.gameObject.SetActive(true);
StartCoroutine(particleKeep);
toxicSpew.Emit(10);
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if(collision.gameObject.name == "Player")
{
collision.transform.SetParent(null);
timeToResetSize = true;
//toxicSpew.gameObject.SetActive(false);
toxicSpew.Stop();
}
}
private void FixedUpdate()
{
if (timeToResetSize == true)
{
counterToReset-=.5f;
if (counterToReset == 0f)
{
IncreaseColliderSize();
}
}
if(triggerDisableCounter == true)
{
counterTillDisable -= 1f;
if(counterTillDisable == 0f)
{
toxicSpew.gameObject.SetActive(false);
}
}
}
void ReduceColliderSize()
{
//movingBC2D.size = reduction;
if (movingBC2D.size.y > 1f)
movingBC2D.size = new Vector2(movingBC2D.size.x, movingBC2D.size.y - 0.1f);
else if(movingBC2D.size.y <= 1f)
movingBC2D.size = movingBC2D.size;
}
/*void RunTimerTillReset()
{
counterToReset = counterToReset - 1;
}
*/
void IncreaseColliderSize()
{
timeToResetSize = false;
counterToReset = 50f;
movingBC2D.size = initialSize;
}
/*private IEnumerator sink(float waitTime = 1f)
{
while (true)
{
ReduceColliderSize();
yield return new WaitForSeconds(waitTime);
}
}*/
private IEnumerator WaitForParticle(float waitTime)
{
while (true)
{
toxicSpew.gameObject.SetActive(true);
yield return new WaitForSeconds(waitTime);
triggerDisableCounter = true;
}
}
}