public void InvalidValueForDamage() { int maxHealth = Random.Range(1, 100); GameObject unit = CreateDefaultEnemyWithStats(CreateUnitStats(maxHealth, 1, 1.5f)); UnitHealth unitHealth = unit.GetComponent <UnitHealth>(); unitHealth.TakeDamage(0); Assert.AreEqual(unitHealth.currentHealth, maxHealth); unitHealth.TakeDamage((int)Random.Range(-1000, 0)); Assert.AreEqual(unitHealth.currentHealth, maxHealth); }
public void UnitSuccesfullyTakesDamage() { int maxHealth = Random.Range(2, 10); GameObject unit = CreateDefaultEnemyWithStats(CreateUnitStats(maxHealth, 1, 1.5f)); UnitHealth unitHealth = unit.GetComponent <UnitHealth>(); unitHealth.TakeDamage(1); Assert.GreaterOrEqual(unitHealth.currentHealth, 1); unitHealth.TakeDamage(maxHealth); Assert.Less(unitHealth.currentHealth, 0); Assert.AreEqual(unitHealth.alive, false); }
void AttackTarget() { targetHealth = currentTarget.GetComponent <UnitHealth>(); //gameObject.transform.LookAt(currentTarget.transform); targetHealth.TakeDamage(damage); }
IEnumerator GiveDamage(UnitHealth unitHealth) { damageGiven = true; unitHealth.TakeDamage(); yield return(new WaitForSeconds(damageRate)); damageGiven = false; }
public void hitPlayer(UnitHealth uh) { if (!hittingPlayerThisFrame) { hittingPlayerThisFrame = true; //Debug.Log("HIT PLAYER"); uh.TakeDamage(1, 0, transform.position, true, false); PlayerRun.slowDown(); } }
private void OnTriggerEnter2D(Collider2D other) { Debug.Log("Collision!"); UnitHealth health = other.gameObject.GetComponent <UnitHealth>(); if (health != null) { health.TakeDamage(_damage); } }
private void dealDamage(GameObject go) { UnitHealth uh = go.GetComponent <UnitHealth>(); if (uh != null) { //Debug.Log (otherPost); uh.TakeDamage(myDamage, knockback, this.transform.position, lateralKnockback); } }
public void Tick(EffectController target) { if ((Time.time - lastTick) >= TickFrequency) { if (targetHealth != null) { targetHealth.TakeDamage(damage); } lastTick = Time.time; } }
public void DealDirectDamage() { try { target.TakeDamage(directDamage); } catch { return; } }
private void Shoot() { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the light. gunLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. UnitHealth enemyHealth = shootHit.collider.GetComponent <UnitHealth> (); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); hitParticles.transform.position = shootHit.point; //hitParticles.transform.rotation = shootHit.transform.rotation; // And play the dsfasdfparticles. //enemyAudio.clip = deathClip; hitParticles.Play(); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
public void UnitKill() { int maxHealth = Random.Range(1, 100); GameObject unit = CreateDefaultEnemyWithStats(CreateUnitStats(maxHealth, 1, 1.5f)); UnitHealth unitHealth = unit.GetComponent <UnitHealth>(); bool status = unitHealth.TakeDamage((int)Random.Range(maxHealth, 1000)); Assert.LessOrEqual(unitHealth.currentHealth, 0); Assert.AreEqual(status, true); Assert.AreEqual(unitHealth.alive, false); }
void AttackTarget() { targetHealth = currentTarget.GetComponent <UnitHealth>(); targetHealth.TakeDamage(damage); }
void TakeDamage() { unitHealth.TakeDamage(damageAmount); }