public void OnTriggerStay(Collider other) { if (other.tag == Tags.CRATE) { crateManager.RemoveCrate(other.gameObject); Destroy(other.gameObject); HealthScript health = null; if (gameObject.GetComponent <HealthScript>()) { health = gameObject.GetComponent <HealthScript>(); } else if (gameObject.GetComponentInParent <HealthScript>()) { health = gameObject.GetComponentInParent <HealthScript>(); } if (health != null) { health.ApplyRegeneration(regenTimePerCrate, regenAmtPerSec); } } else if (other.tag == Tags.POWERUP) { PowerupInfo info = other.gameObject.GetComponent <PowerupInfo>(); _powerupActivator.ActivatePowerup(info); Destroy(other.gameObject); } }
public void UpdateState() { //First try to go for the nearest Crate Transform nearestCrate = CrateManager.GetClosestCrate(transform.position).transform; Vector3 deltaVec = nearestCrate.position - transform.position; if (deltaVec.magnitude < Behaviour.CrateDetectionRange) { Behaviour.SetTargetDestination(nearestCrate.position); if (deltaVec.magnitude < Behaviour.CratePickupRange) { CrateManager.RemoveCrate(nearestCrate.gameObject); Destroy(nearestCrate.gameObject); health.ApplyRegeneration(RegenDuration, RegenPerSecond); } } //If all the crates are out of range, try to hide in the middle of the swarm else { Behaviour.SetTargetDestination(Behaviour.Flocking.calculateLocalSwarmCenter()); } }