-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPillarMovement.cs
More file actions
60 lines (51 loc) · 1.71 KB
/
PillarMovement.cs
File metadata and controls
60 lines (51 loc) · 1.71 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
using UnityEngine;
public class PillarMover : MonoBehaviour
{
[Header("Pillar Settings")]
public float cycleDuration = 3.0f;
public float height = 5.0f;
public float offset = 0.0f;
[Range(0, 1)]
public float upTimePercent = 0.85f;
[Header("Shadow Settings")]
public Transform shadowObject;
public float shadowRange = 2.0f;
private Vector3 pillarStartPos;
private Vector3 shadowStartPos;
void Start()
{
pillarStartPos = transform.position;
if (shadowObject != null) shadowStartPos = shadowObject.position;
new WaitForSeconds(offset);
}
void Update()
{
// Calculate 'Slow Up, Fast Down'
float cycleProgress = (Time.time / cycleDuration) % 1.0f;
float movementFactor = 0f;
if (cycleProgress < upTimePercent)
movementFactor = Mathf.SmoothStep(0, 1, cycleProgress / upTimePercent);
else
{
float downProgress = (cycleProgress - upTimePercent) / (1f - upTimePercent);
movementFactor = 1.0f - downProgress;
}
transform.position = pillarStartPos + Vector3.up * (movementFactor * height);
if (shadowObject != null)
shadowObject.position = shadowStartPos + (shadowObject.up * (movementFactor * shadowRange));
}
// --- COLLISION DETECTION ---
private void OnTriggerEnter2D(Collider2D other)
{
// Check if the object we touched is tagged as "Player"
if (other.CompareTag("Player"))
{
var player = other.GetComponent<Playermove>();
if (player != null)
{
player.die();
Debug.Log("Pillar crushed the player!");
}
}
}
}