-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoinLock.cs
More file actions
36 lines (32 loc) · 876 Bytes
/
CoinLock.cs
File metadata and controls
36 lines (32 loc) · 876 Bytes
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
using UnityEngine;
using UnityEngine.UI;
public class CoinLock : MonoBehaviour
{
private Rigidbody2D rb;
private float stationaryTime = 0f;
private bool isMaterialRemoved = false;
private float velocityThreshold = 20f; // Tune as needed
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
if (isMaterialRemoved || rb == null)
return;
if (rb.velocity.magnitude < velocityThreshold)
{
stationaryTime += Time.deltaTime;
if (stationaryTime >= 0.5f)
{
rb.sharedMaterial = null; // Remove the "Bounce" Physics Material
rb.bodyType = RigidbodyType2D.Static;
isMaterialRemoved = true;
}
}
else
{
stationaryTime = 0f; // Reset if moving
}
}
}