How to change default physics material via script,
I want to change the value "Default Material" in PhysicsManager via script dynamicly. Is there a way? Thanks!,
Answer by tazshelby2016 · Jun 22, 2018 at 05:32 PM
Here are the descriptions from Unity's manual.
PhysicMaterial.PhysicMaterial
Creates a new material.
PhysicMaterial
Physics material describes how to handle colliding objects (friction, bounciness).
PhysicMaterial.bounceCombine
Determines how the bounciness is combined.
PhysicMaterial.frictionCombine
Determines how the friction is combined.
PhysicMaterial.staticFriction
The friction coefficient used when an object is lying on a surface.
I know the Physics$$anonymous$$aterial, but i want to change the default material in my project dynamicly. thanks.
Answer by TSWessel · Sep 06, 2021 at 12:56 PM
While you can't swap out the PhysicMaterial object in the default settings through code, you can change the values of a PhysicMaterial object that's already there.
So, for example, you can make a PhysicsMaterial called default_pm, set it as the default material in the project settings, and then change the values (friction, bounciness, etc.) of default_pm.
Also, new PhysicMaterial()
creates exact copies of the default material, or, in the above example, copies of default_pm. This may be useful if you simply need to read the default material without changing it.