forfeiture, abandoning, entry_fee_collection at start

This commit is contained in:
2026-08-14 11:13:01 +05:30
parent 9970488938
commit 74d9fae6e6
54 changed files with 6214 additions and 2576 deletions
+55 -4
View File
@@ -6,6 +6,7 @@ using UnityEngine.EventSystems;
public class Puck : NetworkBehaviour
{
[HideInInspector]public Rigidbody2D rb;
Collider2D col;
[SyncVar]
public bool isSelected;
public LineRenderer lineRenderer;
@@ -30,6 +31,7 @@ public class Puck : NetworkBehaviour
UpdateTeam();
markerStartScale = selectedMarker.localScale;
rb=GetComponent<Rigidbody2D>();
col = GetComponent<Collider2D>();
startPosition = transform.position;
}
@@ -52,7 +54,9 @@ public class Puck : NetworkBehaviour
GameEvents.OnSelectedPuckChanged -= OnSelectedPuckChanged;
GameManager.OnTeamChanged -= OnTeamChanged;
GameManager.instance.DisposePuck(this);
RestoreAfterReset();
if (GameManager.instance != null)
GameManager.instance.DisposePuck(this);
}
public Vector3 lineEnd;
void Update()
@@ -146,10 +150,28 @@ public class Puck : NetworkBehaviour
AudioManager.instance.PlayPuckHit(vol);
}
Coroutine coroutineReset;
bool holdingCollisionLock;
public void Reset(Vector3? position = null, float duration = 0.5f)
{
Vector3 pos = position ?? startPosition;
StartCoroutine(CoroutineReset(pos, duration));
if (coroutineReset != null)
{
StopCoroutine(coroutineReset);
RestoreAfterReset();
}
coroutineReset = StartCoroutine(CoroutineReset(pos, duration));
}
public void SetCollisionsEnabled(bool enabled)
{
if (col != null)
col.enabled = enabled;
if (rb != null && !enabled)
{
rb.linearVelocity = Vector2.zero;
rb.angularVelocity = 0f;
}
}
Coroutine coroutineScheduleReset;
public void ScheduleReset(Vector3 position, float duration = 0.5f){
@@ -188,15 +210,44 @@ public class Puck : NetworkBehaviour
}
IEnumerator CoroutineReset(Vector3 pos, float duration){
if (GameManager.instance != null)
{
GameManager.instance.PushResetCollisionLock();
holdingCollisionLock = true;
}
rb.linearVelocity = Vector2.zero;
rb.angularVelocity = 0f;
float t=0;
Vector3 pos1 = transform.position;
Quaternion rot1 = transform.rotation;
while(t<duration){
t+=Time.deltaTime;
transform.position = Vector3.Lerp(pos1, pos, t/duration);
transform.rotation = Quaternion.Lerp(rot1, Quaternion.identity, t/duration);
float u = Mathf.Clamp01(t/duration);
transform.position = Vector3.Lerp(pos1, pos, u);
transform.rotation = Quaternion.Lerp(rot1, Quaternion.identity, u);
yield return null;
}
transform.position = pos;
transform.rotation = Quaternion.identity;
RestoreAfterReset();
}
void RestoreAfterReset()
{
if (rb != null)
{
rb.linearVelocity = Vector2.zero;
rb.angularVelocity = 0f;
}
if (holdingCollisionLock && GameManager.instance != null)
{
GameManager.instance.PopResetCollisionLock();
holdingCollisionLock = false;
}
coroutineReset = null;
}
}