void Shoot() { // Reset the timer. timer = 0f; gun_light.enabled = true; // Set position for line render gun_line.enabled = true; gun_line.SetPosition(0, gun_now.transform.position); // detecting if shoot anything if (Physics.Raycast(gun_now.transform.position, fpsCam.transform.forward, out where_hit, range)) { // trying to get HP info. Enemy_Health enemyHealth = where_hit.collider.GetComponent <Enemy_Health>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damage, where_hit.point); } // Set the end point for the ray. gun_line.SetPosition(1, where_hit.point); } else { // shoot as far as it can go. gun_line.SetPosition(1, gun_now.transform.position + fpsCam.transform.forward * range); } }
void Shoot() { timer = 0f; gunLight.enabled = true; gunParticles.Stop(); gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); //shootRay.origin은 광선이 시작되는 점 shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, Range, shootableMask)) { Enemy_Health enemyHealth = shootHit.collider.GetComponent <Enemy_Health>(); if (enemyHealth != null) { enemyHealth.TakeDamage(Damage, shootHit.point); } gunLine.SetPosition(1, shootHit.point); // ray가 맞춘 곳에서 광선이 멈춤 } else { //적을 맞추지 않으면 그저 선만 긋는다. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * Range); } }
// Enemy_Health protected void GiveDamage(Enemy_Health target) { target.TakeDamage(damage); }