PD
Size: a a a
PD
F
M
F
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemPoolerTest : MonoBehaviour
{
// Start is called before the first frame update
void Start() {
// ItemPooler test
GameObject TestObj = ItemPooler.instance.GetItemByName(ItemPooler.ItemType.it1, "Test_prefab");
if (TestObj) {
Debug.Log(TestObj.name);
TestObj.transform.parent = Camera.main.transform;
ItemPooler.instance.transform.parent = this.gameObject.transform;
Debug.Log("ItemPool parent name object name: " + ItemPooler.instance.transform.gameObject.name);
Debug.Log("ItemPool root object name: " + ItemPooler.instance.transform.gameObject.name);
}
else Debug.Log("ItemPooler returned null");
}
// Update is called once per frame
void Update()
{
}
}
RE
F
public class ItemPooler : MonoBehaviour {
private static ItemPooler _instance = null;
public static ItemPooler instance {
get {
if (_instance) return _instance;
else {
root = new GameObject("Item Pool");
_instance = root.AddComponent<ItemPooler>();
return _instance;
}
}
}
делаю new GameObject() внутре геттера поля класса от монобихевиора, сам скрипт ни к чему не прикреплён. но статическое поле видно и по геттеру даже создаёт геймобжект, вешает на него экземпляр и далее работает нормально. Но на сцене не вижу его, он создаётся непонятно где, как бы указать конкретную сцену? Просто парента на нужной сцене прописать?if (!instance) instance = this; else { Destroy(instance.gameObject); instance = this; }извиняюсь за панику
M
if (!instance) instance = this; else { Destroy(instance.gameObject); instance = this; }извиняюсь за панику
F
M
M
RE
RE
M
RE
RE
AP
AP
RE
AP
AP