Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Physics.CheckSphere

static function CheckSphere(position: Vector3, radius: float, layerMask: int = DefaultRaycastLayers): bool;

Description

Returns true if there are any colliders overlapping the sphere defined by position and radius in world coordinates.

	var sphereRadius: float;
	
	function WarningNoise() {
		// Play a noise if an object is nearby.
		if (Physics.CheckSphere(transform.position, sphereRadius)) {
			audio.Play();
		}
	}