public override void ShootFrom(Vector3 position, Vector3 direction) { Vector3[] rayOrigins = { new Vector3(0, offset, 0) + position, new Vector3(0, offset / 2, 0) + position, position, new Vector3(0, -offset / 2, 0) + position, new Vector3(0, -offset, 0) + position, }; RaycastHit target; foreach (Vector3 pos in rayOrigins) { if (Physics.Raycast(pos, direction, out target)) { if (target.collider.CompareTag("Demon")) { DemonStats demon = target.collider.gameObject.GetComponent <DemonStats>(); demon.TakeDamage(GetEffectiveDamage(), Owner); return; } } } }
public void Shoot(Vector3 direction) { float angle = Random.Range(-accuracyError, accuracyError) * Mathf.PI / 90; Vector3 actualDirection = new Vector3(direction.x * Mathf.Cos(angle) - direction.z * Mathf.Sin(angle), direction.y, direction.x * Mathf.Sin(angle) + direction.z * Mathf.Cos(angle)); RaycastHit target; if (Physics.Raycast(transform.position, actualDirection, out target)) { if (target.collider.CompareTag("Demon")) { DemonStats demon = target.collider.gameObject.GetComponent <DemonStats>(); demon.TakeDamage(GetEffectiveDamage(), transform); } else if (target.collider.CompareTag("Player")) { PlayerStats player = target.collider.gameObject.GetComponent <PlayerStats>(); player.TakeDamage(GetEffectiveDamage()); } } }