Я делаю игру в единстве ... Мой сценарий разрезает тело меня sh на 2 других тела меня sh. Как я могу добавить скрипт в новое тело во время выполнения?
В каждый блок необходимо добавить скрипт с именем XRGrabInteractable.
foreach(GameObject chunk in pieces){
if(chunk.GetComponent<BoxCollider>()){//change to collider type of first object
Destroy(chunk.GetComponent<BoxCollider>());
}
//Add rigid body if not alread
if(!chunk.GetComponent<Rigidbody>()){//Add Rigid body if not true
chunk.AddComponent<Rigidbody>();
}
//Add Mesh Colider(might interere with xr script that requires collider)
if(!chunk.GetComponent<MeshCollider>()){//If no mesh colider mesh colider for new chunk
chunk.AddComponent<MeshCollider>();//Add Mesh colider if it doesn't exist
chunk.GetComponent<MeshCollider>().convex = true;//Change To Convex Mesh so that it doesn't fall through floor
}
}