void Shoot() { timer = 0f; //gunAudio.Play(); gunLight.enabled = true; //gunParticles.Stop(); //gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { enemyHealth eHealth = shootHit.collider.GetComponent <enemyHealth>(); if (eHealth != null) { eHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void OnTriggerEnter2D(Collider2D hitInfo) { enemyHealth enemy = hitInfo.GetComponent <enemyHealth>(); // Grabs the enemyHealth script component if (enemy != null) { enemy.TakeDamage(damage); Destroy(gameObject); } }
void OnTriggerEnter(Collider other) { if (other.CompareTag(target)) { enemyHealth eHealth = other.GetComponent <enemyHealth>(); if (eHealth != null) { eHealth.TakeDamage(skillDamange, transform.position); } else { playerHealth pHealth = other.GetComponent <playerHealth>(); pHealth.TakeDamage(skillDamange); } } }
void OnTriggerEnter2D(Collider2D hitInfo) { //want to use the enemy takedamage function enemyHealth enemy = hitInfo.GetComponent <enemyHealth>(); //if the enemy is hit if (hitInfo.transform.name == "enemy_AI") { Impact(); enemy.TakeDamage(damage); } // hitting anything else does not do anything except trigger the explosion else { Impact(); } }
protected virtual void OnTriggerEnter(Collider other) { if (other.tag.Equals("Projectile")) { projectileController proj = other.gameObject.GetComponent <projectileController> (); if (proj.m_shooter != this.gameObject) { if (proj.m_shooter.tag.Equals("Player")) { m_healthController.TakeDamage(proj.m_damage); Vector3 shootForce = player.GetComponent <playerShoot> ().m_pushForce *(this.transform.position - proj.m_shooter.transform.position); this.rigidbody.AddForceAtPosition(shootForce, this.transform.position); if (!proj.isPiercing) { Destroy(other.gameObject); } } } } }