-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransitionScript.cs
More file actions
47 lines (40 loc) · 1.34 KB
/
TransitionScript.cs
File metadata and controls
47 lines (40 loc) · 1.34 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
using UnityEngine;
using System.Collections;
public class TransitionScript : MonoBehaviour
{
public float moveDistance = 20f;
public float moveSpeed = 5f;
public float delayBetweenItems = 0.2f;
public TransitionBridgeIn bridgeInScript; // for lvl 5 bridge animation
[ContextMenu("Trigger Rise")] // Allows you to test by right-clicking the component
public void StartBridgeRise()
{
StartCoroutine(RiseSequence());
}
IEnumerator RiseSequence()
{
// Loop through every child of the TransitionSet
foreach (Transform child in transform)
{
StartCoroutine(MoveItem(child));
// Wait before starting the next bridge piece
yield return new WaitForSeconds(delayBetweenItems);
}
// // now call bridge rise
bridgeInScript.PlayIntro();
}
IEnumerator MoveItem(Transform item)
{
Vector3 startPos = item.localPosition;
Vector3 targetPos = startPos - new Vector3(0, moveDistance, 0);
float elapsed = 0;
float duration = 1f / moveSpeed;
while (elapsed < duration)
{
item.localPosition = Vector3.Lerp(startPos, targetPos, elapsed / duration);
elapsed += Time.deltaTime;
yield return null;
}
item.localPosition = targetPos;
}
}