Version: 5.3 (switch to 5.4b)
언어English
  • C#
  • JS

Script language

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

Physics.CheckSphere

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

닫기

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

닫기

취소

Switch to Manual
public static function CheckSphere(position: Vector3, radius: float, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static bool CheckSphere(Vector3 position, float radius, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function CheckSphere(position: Vector3, radius: float, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static bool CheckSphere(Vector3 position, float radius, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static function CheckSphere(position: Vector3, radius: float, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static bool CheckSphere(Vector3 position, float radius, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);

파라미터

position 구체의 반경.
radius 구체의 반경.
layerMask Layer mask는 캡슐 캐스팅을 할 때 선택적으로 콜라이더를 무시할 때에 사용됩니다.
queryTriggerInteraction Specifies whether this query should hit Triggers.

Description

월드 좌표에 radius,/position/에 의해 정의된 구체로 둘러쌓인 collider가 있는 경우 true를 반환합니다.

#pragma strict
public var sphereRadius: float;
var audio: AudioSource;
function Start() {
	audio = GetComponent.<AudioSource>();
}
function WarningNoise() {
	// Play a noise if an object is within the sphere's radius.
	if (Physics.CheckSphere(transform.position, sphereRadius)) {
		audio.Play();
	}
}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float sphereRadius; AudioSource audio; void Start() { audio = GetComponent<AudioSource>(); } void WarningNoise() { // Play a noise if an object is within the sphere's radius. if (Physics.CheckSphere(transform.position, sphereRadius)) { audio.Play(); } } }