-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollapsingPlatform.cs
56 lines (51 loc) · 1.78 KB
/
CollapsingPlatform.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollapsingPlatform : MonoBehaviour {
private float startingSpeed;
public float collapseSpeed;
public GameObject collapsePlatform;
public Transform maximumCollapseDistance;
private BoxCollider2D platformCollider;
public GameObject externalPlatform;
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.name == "Player")
{
platformCollider = collapsePlatform.GetComponent<BoxCollider2D>();
platformCollider.offset = new Vector2(-18f,platformCollider.offset.y);
platformCollider.size = new Vector2(81f, platformCollider.size.y);
startingSpeed = collapseSpeed;
collision.transform.SetParent(gameObject.transform);
StartCoroutine(Collapse());
externalPlatform.SetActive(false);
//StartCoroutine(IncreaseSpeed());
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.name == "Player")
{
collision.transform.SetParent(null);
StopCoroutine(Collapse());
//StopCoroutine(IncreaseSpeed());
//collapseSpeed = startingSpeed;
}
}
private IEnumerator Collapse()
{
while (true)
{
collapsePlatform.transform.position = Vector2.MoveTowards(collapsePlatform.transform.position, maximumCollapseDistance.position, Time.deltaTime * collapseSpeed);
yield return null;
}
}
private IEnumerator IncreaseSpeed()
{
while (true)
{
collapseSpeed += 0.25f;
yield return new WaitForSeconds(1f);
}
}
}