Skip to main content
Added some clarity and example notes.
Source Link

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate Rigidbody to collide to attached to them (Listener) to collide with the trigger and a handler in a component that getshandles what to do if they are triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simply turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need Listeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a Listener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions (interactive cut-scene).

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate Rigidbody to collide to attached to them (Listener) and a handler in a component that gets triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simply turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need Listeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a Listener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions.

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate Rigidbody (Listener) to collide with the trigger and a handler in a component that handles what to do if they are triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simply turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need Listeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a Listener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions (interactive cut-scene).

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

edited body
Source Link

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate Rigidbody to collide to attached to them (Listener) and a handler in a component that gets triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simplesimply turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need Listeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a Listener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions.

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate Rigidbody to collide to attached to them (Listener) and a handler in a component that gets triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simple turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need Listeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a Listener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions.

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate Rigidbody to collide to attached to them (Listener) and a handler in a component that gets triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simply turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need Listeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a Listener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions.

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

Renamed Listener as it's a rigidbody, not a collider.
Source Link

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate colliderRigidbody to collide to attached to them (ListenerColliderListener) and a handler in a component that gets triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simple turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need ListenerColliderListeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a ListenerColliderListener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions.

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate collider attached to them (ListenerCollider) and a handler in a component that gets triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simple turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need ListenerColliders on appropriate enemies and you don't need to use Tags to filter through them. Disabling a ListenerCollider can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions.

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

This assumes that you're not worried about audio occlusion (sound muffling around obstacles like walls etc.).

I would have a circular/spherical trigger collider (SoundCollider) attached to your gun/weapon that is the size / radius of how far you want the sound to travel. When you shoot: it that turns on this SoundCollider. Enemies can have an appropriate Rigidbody to collide to attached to them (Listener) and a handler in a component that gets triggered if they are in range of your SoundCollider.

Couple of Pros I can see to this approach:

  • You can have an easy to edit variable that changes the radius of the SoundCollider, making some weapons quieter than others.
  • You can let Unity handle the events between your Gun sound and the enemies in hearing range.
  • Effects can be applied to the collider if necessary so when it is active a radar on the mini-map (if you need one) can show the area that sound will travel to.
  • As you only need to turn the SoundCollider on or off instead of sending multiple events, it will work regardless of firerate on your weapons as you simple turn it on when you start firing and have a small delay to turn it off once you've stopped.
  • You only need Listeners on appropriate enemies and you don't need to use Tags to filter through them. Disabling a Listener can make a unit "deaf" quite easily if you need them to not hear anything under certain conditions.

It's a concept but can work well, I used something similar to make an AOE damage ability on a unit but the concept is essentially the same - Unit in certain proximity triggers code when ability is active (gun is firing).

Source Link
Loading