Commit 3f2a02af by Philipp Adolf

Make traps respawn after some time

parent 69c3571b
...@@ -4,18 +4,30 @@ using System.Collections; ...@@ -4,18 +4,30 @@ using System.Collections;
public class Trap : MonoBehaviour { public class Trap : MonoBehaviour {
public int damagePoints = 10; public int damagePoints = 10;
public float respawnTime = 5.0f;
// used to store the position while the trap is deactivated
private Vector2 realPosition;
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
{ {
if (other.tag == "Player") if (other.tag == "Player")
{ {
other.GetComponent<PlayerHealth>().changeHealthBy(-damagePoints); other.GetComponent<PlayerHealth>().changeHealthBy(-damagePoints);
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit.
destroyTrap();
} }
} }
public void destroyTrap() public void destroyTrap()
{ {
realPosition = transform.position;
transform.position = new Vector2(100, 100); transform.position = new Vector2(100, 100);
Invoke("Activate", respawnTime);
}
void Activate()
{
transform.position = realPosition;
} }
} }
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