Commit 3df54979 by Philipp Adolf

Fix shields oscilating between players

parent 9fa623ac
...@@ -13,6 +13,8 @@ public class ShieldScript : MonoBehaviour ...@@ -13,6 +13,8 @@ public class ShieldScript : MonoBehaviour
// used to store the position while the trap is deactivated // used to store the position while the trap is deactivated
private Vector2 spawnPosition; private Vector2 spawnPosition;
public float relayDelay = 0.25f;
private bool canRelay = true;
// Use this for initialization // Use this for initialization
void Start() void Start()
...@@ -23,7 +25,7 @@ public class ShieldScript : MonoBehaviour ...@@ -23,7 +25,7 @@ public class ShieldScript : MonoBehaviour
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
{ {
PlayerHealth oldHealth = parentHealth; PlayerHealth oldHealth = parentHealth;
if (other.tag == "Player") if (canRelay && other.tag == "Player")
{ {
Invoke("stopShielding", shieldingTime); Invoke("stopShielding", shieldingTime);
parentHealth = other.GetComponent<PlayerHealth>(); parentHealth = other.GetComponent<PlayerHealth>();
...@@ -31,11 +33,18 @@ public class ShieldScript : MonoBehaviour ...@@ -31,11 +33,18 @@ public class ShieldScript : MonoBehaviour
transform.parent = other.transform; transform.parent = other.transform;
Debug.Log("Set shield from shield"); Debug.Log("Set shield from shield");
parentHealth.setShield(true); parentHealth.setShield(true);
canRelay = false;
Invoke("enableRelay", relayDelay);
} }
if (oldHealth != null && oldHealth != parentHealth) oldHealth.setShield(false); if (oldHealth != null && oldHealth != parentHealth) oldHealth.setShield(false);
} }
void enableRelay()
{
canRelay = true;
}
void stopShielding() void stopShielding()
{ {
CancelInvoke("stopShielding"); CancelInvoke("stopShielding");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment