言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Physics.OverlapSphere

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.

Close

Sumbission failed

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

Close

Cancel

public static function OverlapSphere(position: Vector3, radius: float, layerMask: int = AllLayers): Collider[];
public static Collider[] OverlapSphere(Vector3 position, float radius, int layerMask = AllLayers);
public static def OverlapSphere(position as Vector3, radius as float, layerMask as int = AllLayers) as Collider[]

Description

球体の内部や触れたすべてのコライダーの配列を取得します

注意: 現在は実際のコライダに対してではなく、コライダの境界部分に対してのみチェックを行ないます。

	// Call a damage function on all objects caught in the
	// radius of an explosion.
	function ExplosionDamage(center: Vector3, radius: float) {
		var hitColliders = Physics.OverlapSphere(center, radius);
		
		for (var i = 0; i < hitColliders.Length; i++) {
			hitColliders[i].SendMessage("AddDamage");
		}
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void ExplosionDamage(Vector3 center, float radius) {
        Collider[] hitColliders = Physics.OverlapSphere(center, radius);
        int i = 0;
        while (i < hitColliders.Length) {
            hitColliders[i].SendMessage("AddDamage");
            i++;
        }
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def ExplosionDamage(center as Vector3, radius as float) as void:
		hitColliders as (Collider) = Physics.OverlapSphere(center, radius)
		i as int = 0
		while i < hitColliders.Length:
			hitColliders[i].SendMessage('AddDamage')
			i++