public void EntityStatsController_TakeDamage_ShouldReducePlayerHealth() { float damage = 50f; EntityStatsController fakeAttacker = new GameObject().AddComponent <EntityStatsController>(); float oldPlayerHealth = entityStats.health.CurrentValue; entityStats.TakeDamage(fakeAttacker, damage); float newPlayerHealth = entityStats.health.CurrentValue; Assert.IsTrue(oldPlayerHealth > newPlayerHealth); }
private void OnTriggerEnter(Collider other) { GameObject col = other.gameObject; // if other object is a player then deal damage if (col.CompareTag("Player")) { EntityStatsController target = col.GetComponent <EntityStatsController>(); target.TakeDamage(Random.Range(minDamage, maxDamage)); gameObject.SetActive(false); } else if (col.CompareTag("Ground")) { // Damage any players within impact radius float damage = Random.Range(minDamage, maxDamage); foreach (GameObject player in PlayerManager.Instance.AlivePlayers) { if (Vector3.Distance(transform.position, col.transform.position) <= impactRadius) { player.GetComponent <EntityStatsController>().TakeDamage(damage); } } gameObject.SetActive(false); } }
protected override void OnTriggerEnter(Collider other) { GameObject col = other.gameObject; // Ignore collisions with launcher or if currently being held if (col == LauncherStats.gameObject || _interactable.IsPickedUp) { return; } // if other object is a player, deal damage if (col.CompareTag("Player")) { EntityStatsController target = col.GetComponent <EntityStatsController>(); target.TakeDamage(LauncherStats, Damage); } else if (col.CompareTag("Enemy") && LaunchedByPlayer) { RhakStatsController target = col.GetComponent <RhakStatsController>(); // Ensure that the boss was hit if (target) { target.TakeDamageFromOrb(_colour); } } // Don't worry about collisions with colliders that are triggers if (!other.isTrigger) { gameObject.SetActive(false); } }
/// <summary> /// Perform damage on a target /// </summary> /// <param name="targetStats">Target's stats</param> /// <param name="damageValue">Damage value to apply</param> /// <param name="damageDelay">Time to wait before damage is applied</param> protected IEnumerator PerformDamage(EntityStatsController targetStats, float damageValue, float damageDelay = 0f) { if (damageDelay > 0f) { yield return(new WaitForSeconds(damageDelay)); } // Applies damage to targetStats targetStats.TakeDamage(Stats, damageValue); }
protected override void OnTriggerEnter(Collider other) { GameObject col = other.gameObject; // if other object is an enemy, deal damage if (col.CompareTag(TargetTag)) { EntityStatsController target = col.GetComponent <EntityStatsController>(); target.TakeDamage(LauncherStats, Damage); } // Don't worry about collisions with the launcher or colliders that are triggers if (col != LauncherStats.gameObject && !other.isTrigger && other.tag != AllyTag) { gameObject.SetActive(false); } }
protected override void OnTriggerEnter(Collider other) { GameObject col = other.gameObject; // if other object is an enemy, deal damage if (col.CompareTag(TargetTag)) { EntityStatsController target = col.GetComponent <EntityStatsController>(); target.StartCoroutine(other.transform.GetComponent <PlayerMotorController>().ApplyTimedMovementModifier(0.35f, 1.5f)); target.TakeDamage(LauncherStats, Damage); } // Don't worry about collisions with the launcher or colliders that are triggers if (col != LauncherStats.gameObject && !other.isTrigger && other.tag != AllyTag) { InstantiateExplosion(); gameObject.SetActive(false); } }
protected override void OnTriggerEnter(Collider other) { GameObject col = other.gameObject; // if collision is with a player then deal damage if (col.CompareTag("Player")) { EntityStatsController target = col.GetComponent <EntityStatsController>(); target.StartCoroutine(other.transform.GetComponent <PlayerMotorController>().ApplyTimedMovementModifier(0.5f, 1.5f)); target.TakeDamage(Damage); gameObject.SetActive(false); } else if (col.CompareTag("Ground")) { // Possibly spawn a random plant if (Random.Range(0f, 1f) < spawnPlantProbability) { int maxIndex = 1; float healthPercentage = LauncherStats.health.CurrentValue / LauncherStats.health.maxValue; if (healthPercentage < 0.35f) { maxIndex = 4; } else if (healthPercentage < 0.7f) { maxIndex = 3; } TreantBossCombatController treatCombat = LauncherStats.GetComponent <TreantBossCombatController>(); if (treatCombat && treatCombat.CanSpawnNewPlant()) { GameObject plantPrefab = plantPrefabs[Random.Range(0, maxIndex)]; GameObject plant = Instantiate(plantPrefab, new Vector3(transform.position.x, 0, transform.position.z), Quaternion.identity); treatCombat.AddPlantToSpawnList(plant); } } gameObject.SetActive(false); } }