【发布时间】:2022-11-10 22:01:51
【问题描述】:
游戏对象 b 是一颗不会杀死的流星,但会显示真正的流星(a)会在哪里产卵。继承人的代码:
IEnumerator hard()
{
while(true)
{
x1 = Random.Range(-10, 10);
y1 = Random.Range(6, -6);
x2 = Random.Range(-10, 10);
y2 = Random.Range(6, -6);
x3 = Random.Range(-10, 10);
y3 = Random.Range(6, -6);
Instantiate(b, new Vector3(x1, y1, 0), Quaternion.identity);
Instantiate(b, new Vector3(x2, y2, 0), Quaternion.identity);
Instantiate(b, new Vector3(x3, y3, 0), Quaternion.identity);
yield return new WaitForSeconds(2);
Instantiate(a, new Vector3(x1, y1, 0), Quaternion.identity);
Instantiate(a, new Vector3(x2, y2, 0), Quaternion.identity);
Instantiate(a, new Vector3(x3, y3, 0), Quaternion.identity);
}
}
IEnumerator clean()
{
Destroy(b, 1);
yield return new WaitForSeconds(5);
}
错误信息是:
不允许破坏资产以避免数据丢失。 如果您真的想删除资产,请使用 DestroyImmediate (theObject, true);
我不需要销毁资产,只销毁场景中的游戏对象,如何?
即使我不需要它,我也尝试使用 DestroyImmediate(),但它仍然说没有权限。
【问题讨论】:
-
不确定,但可能创建一个实例化对象的游戏对象变量,然后销毁游戏对象变量应该可以工作。试试这个:
Gameobject gameObjectB = Instantiate(b, new Vector3(x1, y1, 0), Quaternion.identity);然后Destroy(gameObjectB, 1)