void OnTriggerEnter(Collider other) { if (other.tag == "Player") { GameObject HPBar = GameObject.FindWithTag("HealthPoint"); HealthPoint HP = null; if (HPBar) { HP = HPBar.GetComponent <HealthPoint> (); } if (HP) { Vector3 direction = (transform.position - other.gameObject.transform.position).normalized; HP.TakeDamage(damage, direction); } } if (other.gameObject.layer == LayerMask.NameToLayer("Enemy")) { EnemyHealth HP = other.gameObject.GetComponent <EnemyHealth> (); if (HP) { HP.TakeDamage(damage * 2, Vector3.zero); } } // If it's flammable block. FlammableBlock block = other.gameObject.GetComponent <FlammableBlock> (); if (block) { block.TakeHit(damage); } }
void Shoot() { timer = 0f; gunAudio.volume = gunVolume; 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)) { FlammableBlock block = shootHit.collider.GetComponent <FlammableBlock> (); EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); if (enemyHealth) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } else if (block) { block.TakeHit(1, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }