- Home /
Error with changing 2D physics material through a script
I'm trying to change a 2D physics material through a script, but I keep getting an error that I don't understand considering I'm pretty sure I'm doing everything correctly according to this post, although it is working with 3D physics materials: https://answers.unity.com/questions/1485212/how-do-i-change-a-physics-material-through-a-scrip.html
Here's my code:
if (Bouncy)
{
playerCollider.material = playerBouncyPhysicsMaterial;
} else
{
playerCollider.material = playerPhysicsMaterial;
}
as a side note, playerCollider is a Collider2D.
Here's the error.
Assets\Scripts\PlayerController.cs(149,26): error CS1061: 'Collider2D' does not contain a definition for 'material' and no accessible extension method 'material' accepting a first argument of type 'Collider2D' could be found (are you missing a using directive or an assembly reference?)
I really don't understand why this is happening. Can anyone help me? thanks.
Your answer
Follow this Question
Related Questions
I have problem destroying my objects 1 Answer
Stuck Between tilemap colliders 0 Answers
Use transform.position in FixedUpdate to ensure collision with objects which have Velocity 0 Answers
Workarounds for Higher Control When Using Physics2D? 0 Answers
How to destroy gameobjects with same tag using RaycastHit2D? 1 Answer