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)) { EnemyLife enemyHealth = shootHit.collider.GetComponent <EnemyLife> (); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void HitAnEnemy(EnemyLife enemyLife) { if(!enemyLifesHit.Contains(enemyLife)){ enemyLifesHit.Add(enemyLife); enemyLife.TakeDamage(damage); if(destroyOnHitEnemy){ Destroy(gameObject); } } }
// Update is called once per frame void Update() { if (target != null) { transform.position = Vector3.SmoothDamp(transform.position, target.transform.position, ref velocity, 0.05f); relative = target.transform.position - transform.position; distanceToEnemy = relative.magnitude; // If it has reached its target then display the take damage effect, decrease the enemy's life and destroy the bullet if (distanceToEnemy < 0.1) { enemyLifeScript = target.GetComponent <EnemyLife> (); if (tower != null && (tower.GetComponent <Weapon>().TakeDamageEnemyEffect != null || tower.GetComponent <MultiShotWeapon>().TakeDamageEnemyEffect != null)) { Weapon weapon; if (tower.GetComponent <Weapon>().TakeDamageEnemyEffect != null) { weapon = tower.GetComponent <Weapon>(); } else { weapon = tower.GetComponent <MultiShotWeapon>(); } weapon.effect = (GameObject)Instantiate(weapon.TakeDamageEnemyEffect, target.transform.position, target.transform.rotation); weapon.effect.transform.parent = tower.transform; } enemyLifeScript.TakeDamage(1); Destroy(gameObject); } } else { Destroy(gameObject); } }