Another way to check if player is in sphere/box area than using triggers
I'm currently making my own reverb zone and i don't know way how to check if the player is in specific radius / range. The reason why i'm not using OnTriggerEnter etc. is there is no blending, so if two triggers are on top of each other, it will not call the triggerenter function. So i just need way to check if player is on range.
Answer by alankemp · May 16, 2017 at 07:47 PM
Vector3.Distance can tell you how far apart two positions are. If you attach the script to the reverb zone object you can check "transform.position" and your players transform position and see how far apart they are.
Maybe something like this:
public class MyZone : MonoBehaviour
{
public GameObject ThePlayer;
public float Radius;
void Update()
{
float dist = Vector3.Distance(ThePlayer.transform.position, transform.position);
if (dist < Radius)
{
// the player is within radius distance of this object
}
}
}
This would perfectly work with sphere radius, but what about box? The one reason why i'm making my own reverb zone is cause the default has only the sphere shape.
Your answer
![](https://koobas.hobune.stream/wayback/20220612122017im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
audio filters cutoff (Unity 2017.2) 0 Answers
Reverb Zones bypassing AudioListener.Volume 0 Answers
Is there a way to get the audio form mobile mic and find it's music key ? Like in a karaoke game. 0 Answers
Listening to Sound Card Output 0 Answers
Help destroying a seperate game object on collision enter 1 Answer