我有代码来销毁一个立方体GameObject时,它与地形碰撞。然而,我不确定在销毁多维数据集之后如何实例化一个新的球体GameObject来代替它。
这是当前的代码:
{
void OnCollisionEnter(Collision collision)
{
if (collision.collider.gameObject.tag != "Destroy")
{
Destroy (gameObject);
}
}}
发布于 2020-04-18 10:49:56
1)将此脚本附加到地形游戏对象,而不是立方体。
2)在编辑器中为多维数据集对象(例如多维数据集)添加新的标签。
3)创建一个新的球体预制实例,您可以通过包含OnCollisionEnter()事件的脚本进行访问。
void OnCollisionEnter(Collision collision)
{
if (collision.collider.gameObject.tag == "Cube")
{
//store the transform component of the gameobject to be destroyed.
var transf = collision.gameObject.transform;
//Destroy the collided gameobject
DestroyImmediate(gameObject);
//Instantiate in the position and rotation of the destroyed object.
Instantiate(sphere, transf.position, transf.rotation);
}
}https://stackoverflow.com/questions/61283522
复制相似问题