forfeiture, abandoning, entry_fee_collection at start
This commit is contained in:
+54
-3
@@ -15,22 +15,73 @@ public class Ball : NetworkBehaviour
|
||||
void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
col = GetComponent<Collider2D>();
|
||||
startPosition = transform.position;
|
||||
}
|
||||
|
||||
Collider2D col;
|
||||
Coroutine coroutineReset;
|
||||
bool holdingCollisionLock;
|
||||
|
||||
public void SetCollisionsEnabled(bool enabled)
|
||||
{
|
||||
if (col != null)
|
||||
col.enabled = enabled;
|
||||
if (rb != null && !enabled)
|
||||
{
|
||||
rb.linearVelocity = Vector2.zero;
|
||||
rb.angularVelocity = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset(float duration){
|
||||
StartCoroutine(CoroutineReset(duration));
|
||||
if (coroutineReset != null)
|
||||
{
|
||||
StopCoroutine(coroutineReset);
|
||||
RestoreAfterReset();
|
||||
}
|
||||
coroutineReset = StartCoroutine(CoroutineReset(duration));
|
||||
}
|
||||
|
||||
IEnumerator CoroutineReset(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, startPosition, t / duration);
|
||||
transform.rotation = Quaternion.Lerp(rot1, Quaternion.identity, t/duration);
|
||||
float u = Mathf.Clamp01(t / duration);
|
||||
transform.position = Vector3.Lerp(pos1, startPosition, u);
|
||||
transform.rotation = Quaternion.Lerp(rot1, Quaternion.identity, u);
|
||||
yield return null;
|
||||
}
|
||||
transform.position = startPosition;
|
||||
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;
|
||||
}
|
||||
|
||||
public bool touchingB,touchingL,touchingR,touchingT = false;
|
||||
|
||||
Reference in New Issue
Block a user