Commit ae42e08e by Alisa Jung

respawn for powerups, fire and shield.

TODO for Tim: Add Bullet prefabs to Player, Add Tag "Trap" to Trap prefab.
parent 765fd15d
...@@ -20,7 +20,6 @@ public class Bullet : MonoBehaviour ...@@ -20,7 +20,6 @@ public class Bullet : MonoBehaviour
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
{ {
//Debug.Log("Bullet colide with " + other.name);
if (healingPoints > 0 && other.tag == "Player") if (healingPoints > 0 && other.tag == "Player")
{ {
other.GetComponent<PlayerHealth>().changeHealthBy(healingPoints); other.GetComponent<PlayerHealth>().changeHealthBy(healingPoints);
...@@ -28,6 +27,7 @@ public class Bullet : MonoBehaviour ...@@ -28,6 +27,7 @@ public class Bullet : MonoBehaviour
} }
else if (destroyTrap && other.tag == "Trap") else if (destroyTrap && other.tag == "Trap")
{ {
//TODO für Tim: ACHTUNG Trap braucht Tag Trap.
other.GetComponent<Trap>().destroyTrap(); other.GetComponent<Trap>().destroyTrap();
Destroy(gameObject); Destroy(gameObject);
} }
......
...@@ -12,10 +12,13 @@ public class FireScript : MonoBehaviour ...@@ -12,10 +12,13 @@ public class FireScript : MonoBehaviour
private Vector3 startScale; //fixes a bug: scale of fire was 0 when attached to the player. private Vector3 startScale; //fixes a bug: scale of fire was 0 when attached to the player.
private Vector2 spawnPosition;
public float respawnTime = 5.0f;
void Start() void Start()
{ {
startScale = transform.localScale; startScale = transform.localScale;
spawnPosition = transform.position;
} }
// Update is called once per frame // Update is called once per frame
...@@ -31,16 +34,24 @@ public class FireScript : MonoBehaviour ...@@ -31,16 +34,24 @@ public class FireScript : MonoBehaviour
{ {
if (other.tag == "Player") if (other.tag == "Player")
{ {
Invoke("stopBurning", burningTime);
parentHealth = other.GetComponent<PlayerHealth>(); parentHealth = other.GetComponent<PlayerHealth>();
transform.position = other.transform.position; //hier schon position setzen transform.position = other.transform.position; //hier schon position setzen
transform.parent = other.transform; transform.parent = other.transform;
transform.localScale = startScale; transform.localScale = startScale;
Invoke("stopBurning", burningTime);
} }
} }
void stopBurning() void stopBurning()
{ {
Destroy(gameObject); CancelInvoke("stopBurning");
parentHealth = null;
transform.position = new Vector2(100, 100);
Invoke("Activate", respawnTime);
}
void Activate()
{
transform.position = spawnPosition;
} }
} }
...@@ -253,7 +253,7 @@ public class PlayerControl : MonoBehaviour ...@@ -253,7 +253,7 @@ public class PlayerControl : MonoBehaviour
private void shoot() private void shoot()
{ {
float dir = Mathf.Sign(transform.localScale.x); float dir = -Mathf.Sign(transform.localScale.x);
Vector2 pos = new Vector2(transform.position.x + dir * spawnDistance, transform.position.y); Vector2 pos = new Vector2(transform.position.x + dir * spawnDistance, transform.position.y);
switch (powerUpType) switch (powerUpType)
......
...@@ -12,12 +12,28 @@ public class PowerUpScript : MonoBehaviour ...@@ -12,12 +12,28 @@ public class PowerUpScript : MonoBehaviour
/// </summary> /// </summary>
public int type; public int type;
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<PlayerControl>().setPowerUpType(type); other.GetComponent<PlayerControl>().setPowerUpType(type);
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit. destroyPowerUp();
} }
} }
public void destroyPowerUp()
{
realPosition = transform.position;
transform.position = new Vector2(100, 100);//TODO setze auf 1000 oder so, zur sicherheit.
Invoke("Activate", respawnTime);
}
void Activate()
{
transform.position = realPosition;
}
} }
...@@ -8,10 +8,16 @@ public class ShieldScript : MonoBehaviour ...@@ -8,10 +8,16 @@ public class ShieldScript : MonoBehaviour
public float shieldingTime = 10; public float shieldingTime = 10;
public float respawnTime = 5.0f;
// used to store the position while the trap is deactivated
private Vector2 spawnPosition;
// Use this for initialization // Use this for initialization
void Start() void Start()
{ {
Invoke("stopShielding", shieldingTime); spawnPosition = transform.position;
} }
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
...@@ -19,6 +25,7 @@ public class ShieldScript : MonoBehaviour ...@@ -19,6 +25,7 @@ public class ShieldScript : MonoBehaviour
PlayerHealth oldHealth = parentHealth; PlayerHealth oldHealth = parentHealth;
if (other.tag == "Player") if (other.tag == "Player")
{ {
Invoke("stopShielding", shieldingTime);
parentHealth = other.GetComponent<PlayerHealth>(); parentHealth = other.GetComponent<PlayerHealth>();
transform.position = other.transform.position; //hier schon position setzen transform.position = other.transform.position; //hier schon position setzen
transform.parent = other.transform; transform.parent = other.transform;
...@@ -31,7 +38,15 @@ public class ShieldScript : MonoBehaviour ...@@ -31,7 +38,15 @@ public class ShieldScript : MonoBehaviour
void stopShielding() void stopShielding()
{ {
CancelInvoke("stopShielding");
if (parentHealth != null) parentHealth.setShield(false); if (parentHealth != null) parentHealth.setShield(false);
Destroy(gameObject); parentHealth = null;
transform.position = new Vector2(100, 100);
Invoke("Activate", respawnTime);
}
void Activate()
{
transform.position = spawnPosition;
} }
} }
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