Hi I have a basic explosion script that pushes all of the boxes around but I want all damaged objects mesh to be changed
Just to test if it is working I’m just using Cubes for now and trying to change any damages objects to Spheres
public float force;
public float radius;
public GameObject explosion;
Mesh box;
void Update (){
if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast (ray, out hit, 70))
{
GameObject explo = Instantiate(explosion, hit.point, Quaternion.identity) as GameObject;
Destroy (explo, 3);
Collider[] colliders = Physics.OverlapSphere(hit.point, radius);
foreach(Collider c in colliders)
{
if(c.rigidbody == null) continue;
c.rigidbody.AddExplosionForce(force, hit.point, radius, .5f, ForceMode.Impulse);
box = c.GetComponent<MeshFilter>().mesh;
if(box == "Cube")
{
c.GetComponent<MeshFilter>().mesh = "Sphere";
}
}
}
}
}
}
I’m not quite sure on how to use MeshFilter
I think “box = c.GetComponent().mesh;” is correct but how would I call that in an IF statement and then instantiate it?