Answers for "hwo to check if something is in a sphere in unity"

C#
0

hwo to check if something is in a sphere in unity

public class Test : 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
        }
    }
 }
Posted by: Guest on April-27-2021

Code answers related to "hwo to check if something is in a sphere in unity"

C# Answers by Framework

Browse Popular Code Answers by Language