我在我的遊戲中實施了煙霧預製。這個想法是創建預製件的3個不同的實例(在不同的位置),然後根據切換按鈕銷燬它們。這個問題沒有被破壞,我不知道爲什麼。銷燬預製實例
這是我的腳本:
class Smoke1 : MonoBehaviour
{
public GameObject myPrefab;
public GameObject canvasObject;
public static GameObject newSmoke1;
public static GameObject newSmoke2;
public static GameObject newSmoke3;
public int toggle1;
public int toggle2;
public int toggle3;
public Vector3 smokeposition1 = new Vector3 (397, -394, 90);
public Vector3 smokeposition2 = new Vector3(414, -402, 90);
public Vector3 smokeposition3 = new Vector3(432, -410, 90);
string newSmoke;
void Start()
{
i = 1;
toggle1 = 2;
toggle2 = 2;
toggle3 = 2;
newinstance(smokeposition1, newSmoke1);
newinstance(smokeposition2, newSmoke2);
newinstance(smokeposition3, newSmoke3);
}
void Update()
{
togglecheck(ThermoElectric.t1Bool, toggle1, newSmoke1, smokeposition1);
togglecheck(ThermoElectric.t2Bool, toggle2, newSmoke2, smokeposition2);
togglecheck(ThermoElectric.t3Bool, toggle3, newSmoke3, smokeposition3);
}
void newinstance(Vector3 smokeposition, GameObject smokeinstance)
{
smokeinstance = Instantiate(myPrefab, smokeposition, Quaternion.Euler(-90, 0, 0)) as GameObject;
smokeinstance.transform.SetParent(canvasObject.transform, false);
smokeinstance.transform.localScale = new Vector3(1, 1, 1);
smokeinstance.GetComponent<ParticleSystem>().startColor = new Color(0.1f, 0.1f, 0.1f, 1);
}
void togglecheck(bool turbine, int togglei, GameObject smokeinstancet, Vector3 smokeposition)
{
if (turbine == true && togglei == 1)
{
newinstance(smokeposition, smokeinstancet);
togglei = 2;
}
if (turbine == false && togglei == 2)
{
Destroy(smokeinstancet, 0.1f);
togglei = 1;
}
}
}
的布爾變量正在和如果條件得到滿足,但destroyed..Can你幫組合屋沒有得到?
https://docs.unity3d.com/ScriptReference/Object.Destroy。html 你什麼時候檢查過你的元素是否已經被刪除? _「實際的物體破壞總是延遲到當前更新循環之後,但總是在渲染之前完成。」_ – TripleEEE
當遊戲運行時,我看到當我更改切換時,預製件不會被破壞。 –
我看不出延遲的原因,循環應該馬上完成。 –