Commit 36b53389 by Philipp Adolf

Change behavior of trap destroyers

Instead of acting as a bullet power up it now immediately destroys a trap on pickup. The trap closest to any player (excluding the player that picked up the destroyer) is destroyed.
parent 52ad2aa7
......@@ -237,7 +237,6 @@ public class PlayerControl : MonoBehaviour
public const int POWERUP_NONE = 0;
public const int POWERUP_HEALINGBULLET = 1;
public const int POWERUP_TRAPDESTROYER = 2;
private int powerUpType = POWERUP_NONE;
......@@ -246,7 +245,6 @@ public class PlayerControl : MonoBehaviour
public float coolDownTime = 2.0f;
public GameObject healingBulletPrefab;
public GameObject trapDestroyingBulletPrefab;
/// <summary>
/// Falls das im Editor falsch ist: Auf 0.2 setzen.
......@@ -269,10 +267,6 @@ public class PlayerControl : MonoBehaviour
GameObject bullet = Instantiate(healingBulletPrefab, pos, transform.rotation) as GameObject;
bullet.GetComponent<Bullet>().shoot(new Vector2(dir, 0));
break;
case POWERUP_TRAPDESTROYER:
GameObject trapbullet = Instantiate(trapDestroyingBulletPrefab, pos, transform.rotation) as GameObject;
trapbullet.GetComponent<Bullet>().shoot(new Vector2(dir, 0));
break;
default:
break;
}
......
......@@ -8,7 +8,6 @@ public class PowerUpScript : MonoBehaviour
/// sollte übereinstimmen mit PlayerControl.POWERUP_XXX
/// 0 == none
/// 1 == Heal
/// 2 == destroyTrap
/// </summary>
public int type;
......
using UnityEngine;
using System.Collections;
public class TrapDestroyer : MonoBehaviour
{
public float respawnTime = 5.0f;
private Vector2 realPosition;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
GameObject bestTrap = null;
float bestDistance = float.PositiveInfinity;
GameObject[] traps = GameObject.FindGameObjectsWithTag("Trap");
foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player"))
{
if (player == other.gameObject)
continue;
foreach (GameObject trap in traps)
{
float distance = (player.transform.position - trap.transform.position).magnitude;
if (distance < bestDistance)
{
bestTrap = trap;
bestDistance = distance;
}
}
if (bestTrap != null)
{
bestTrap.GetComponent<Trap>().destroyTrap();
}
}
DestroyPowerUp();
}
}
void DestroyPowerUp()
{
realPosition = transform.position;
transform.position = new Vector2(1000, 1000);
Invoke("Activate", respawnTime);
}
void Activate()
{
transform.position = realPosition;
}
}
fileFormatVersion: 2
guid: 84f3fefc4de4fd24982fdd4f908396bb
timeCreated: 1433440862
guid: cf4e7b5b5976d4f4fa88ca684f750e96
timeCreated: 1433541614
licenseType: Free
NativeFormatImporter:
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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