So basically I am working on a 3D puzzle game and I need to find out how to destroy a cube, activate the particle system and respawn it when it hits my hazard.
Instead of destroying it, you could simply deactivate the mesh renderer, so it would still be there, including the box collider, which you can then use to detect the collision with the hazard.
You can also attach the particle system to this now invisible cube and spawn them from there.
And How would I do that?
You need a reference to the cube object, from where you can get its components and enable / disable them.
How to get that reference depends on how the effect is triggered. For example a collision, or it’s generally a known object, or you just spawned it and have the reference through that, or…
I assume you have to click on a cube to destroy it.
void Update()
{
RaycastHit hit;
//shoot Ray to cube
if(Physics.Raycast(transform.position, Camera.main.ScreenToWorldPoint(mousePosition), out hit))
{
//Get the MeshRenderer component
MeshRenderer meshRenderer = hit.transform.GetComponent<MeshRenderer>();
//Check if there is a MeshRenderer
if(meshRenderer != null)
{
meshRenderer.enable = false;
}
}
}