前提・実現したいこと
Physics.CheckSphereというメソッドを試してみましたが、これはシーン上で、その検知範囲の球を可視化することってできませんか?
リファレンスを見ると、それらしき引数が見つかりませんでした。
このままだと、とてもテストしづらいなと思いました。
以下、2点質問させてください。
1点目:
ゲーム画面では検知範囲の球が表示されず、シーン上だけで検知範囲の球を表示させる方法ってありませんか?
2点目:
球の検知範囲内にヒットしたオブジェクト情報の取得ってできませんか?
OnCollisionEnterみたいにCollision等取得できませんか?
ヒットしたオブジェクトの条件により、処理の分岐はできないか知りたいです。
試したこと
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Sample : MonoBehaviour { 6 7 [SerializeField] 8 float sphereRadius; 9 10 void Start () { 11 } 12 13 void Update () { 14 if(Physics.CheckSphere(this.transform.position, sphereRadius)){ 15 Debug.Log("hit"); 16 } 17 } 18} 19
追記。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Sample : MonoBehaviour { 6 7 [SerializeField] 8 float sphereRadius = 3.0f; 9 Vector3 center; 10 11 // Use this for initialization 12 void Start () { 13 center = this.transform.position; 14 } 15 16 // Update is called once per frame 17 void Update () { 18 Collider[] hitColliders = Physics.OverlapSphere(center, sphereRadius); 19 int i = 0; 20 while (i < hitColliders.Length) 21 { 22 Debug.Log(hitColliders[i].gameObject); 23 i++; 24 } 25 } 26 27 void OnDrawGizmos(){ 28 Gizmos.color = Color.yellow; 29 Gizmos.DrawWireSphere(center, sphereRadius); 30 } 31}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/11/24 03:28
退会済みユーザー
2018/11/25 07:21
2018/11/25 07:40
退会済みユーザー
2018/11/25 08:19
2018/11/25 10:04
退会済みユーザー
2018/11/25 13:18