提示コードですがPlayer_Spear_Pool
オブジェクトに下記のスクリプトをアタッチしているのですがvoid Start()
でpool
変数に値を設定しても
GetInstance()
関数でDebug.Log("eeeee")が出力されているためpool
変数がnull
いなってしまうのですがこれは何が原因なのでしょうか?
transform.childCount
の値を出力しましたが10と表示されています
cs
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class WeaponPool : MonoBehaviour 6{ 7 Transform[] pool; 8 // Start is called before the first frame update 9 void Start() 10 { 11 Debug.Log("ああああああ" + transform.childCount); 12 pool = new Transform[transform.childCount]; 13 14 for (int i = 0; i < pool.Length; i++) 15 { 16 pool[i] = transform.GetChild(i); 17 } 18 19 } 20 21 // Update is called once per frame 22 void Update() 23 { 24 25 } 26 27 28 29 30 31 /*############################ オブジェクトを返す ############################*/ 32 public Transform GetInstance() 33 { 34 if(pool == null) 35 { 36 Debug.Log("eeee"); 37 } 38 39 40 foreach (Transform t in pool) 41 { 42 if (t.gameObject.activeSelf == false) 43 { 44 t.gameObject.SetActive(true); 45 46 return t; 47 } 48 } 49 50 GameObject obj = Instantiate(pool[0].gameObject,transform); 51 obj.transform.position = transform.position; 52 return obj.transform; 53 54 } 55 56 57} 58
https://ja.stackoverflow.com/questions/88081/
こちらを参照して適切に対応してください。
https://teratail.com/help#posted-otherservice

回答1件
あなたの回答
tips
プレビュー