Hey,
I have this gameObject that changes it PhysicsMaterial2D, on it’s CircleCollider2D during runtime, but it is still acting as if it doesn’t have the Physics Material.
I change it like this:
var yellowPMat : PhysicsMaterial2D;
function Update () {
if (color == 'yellow') {
gameObject.GetComponent(CircleCollider2D).sharedMaterial = yellowPMat;
}
else {
gameObject.GetComponent(CircleCollider2D).sharedMaterial = null;
}
}
I can see in the editor that the material on the CircleCollider2D is changing, but it is not having any effect on the ball’s bounciness (the bounciness in the PMat is 0.9) so I don’t know what’s happening.
I feel like I am missing something, so someone help me please. ![]()
Thanks. ![]()
This fix didn't work me unfortunately! Although I'm using EdgeCollider2D(s), not circle colliders. Just so you know, I had the [same issue][1] and submitted a bug report which Unity accepted. So you weren't doing anything wrong. [1]: http://answers.unity3d.com/questions/579648/change-a-collider-2d-physics-material-at-runtime.html
– hamstarYeah, I feel like my fix wasn't a REAL fix as such, it just seemed like a dodgy way to get it to work, but it did the job in my case anyway. :P
– JtecI must have made a mistake before because I tested it again and it did work (disabling > setting material > enabling). Thanks for the tip.
– hamstarIt works for that single collider but be careful with other colliders. If you have trigger colliders which collides with that enable/disable collider in this second, the trigger won't work.
– LaSuttSuttThis is still a problem in Unity 5 and this solution still works.
– PricklyApps