私は自分のゲームに煙プレハブを実装しています。プレハブの異なる3つのインスタンスを異なる位置に作成し、トグルボタンに従って破棄します。問題は、インスタンスが破壊されていないと私は理由が分からない。 boolsが働いているプレハブインスタンスを破壊する
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 要素が壊れているかどうかをいつ確認しましたか? _ "実際のオブジェクトの破棄は、現在のUpdateループの後まで常に遅延されますが、レンダリングの前に常に行われます。" _ – TripleEEE
ゲームが実行されると、トグルを変更するとプレハブが破棄されないことがわかります。 –
私は遅延の理由を見ない、ループはすぐに終了する必要があります。 –