I added a MeshCollider Component to and object in a c# script. I have this stored in a variable called
MeshCollider mcMeshCollider
I would like to set the Material to a material in Project View Materials/PhysMatRough
I tried the following but the material part didn't work:
GameObject goCurObj;
MeshCollider mcMeshCollider = null;
PhysicMaterial phymMaterial = null;
//goCurObj = ... // Assigned to an object I want to attach the MeshCollider
// Add the MeshCollider - This part worked
mcMeshCollider = goCurObj.AddComponent<MeshCollider>();
// Change Material
// Set the Material to PhysMatRough
// This didn't work and it was null
phymMaterial
= (PhysicMaterial)Resources.Load("Materials/PhysMatRough");
// I tried both but since phymMaterial is null it had no effect.
mcMeshCollider.sharedMaterial = phymMaterial;
or
mcMeshCollider.material = phymMaterial;