- Home /
Change a GameObject's collider
How do you change a GameObject's collider? It appears that you cannot assign collider (read-only var)?
Answer by Berenger · May 03, 2012 at 05:06 AM
The collider property is probably declared like that in Component :
public Collider collider{ get{ return GetComponent(); } }
That's why you can directly affect an other collider to it. To achieve that, you need to destroy the current collider if there is one, then add a new one.
(collider == null) would mean that there is no collider on this object. However, Destroy( null ) won't raise an error, so you can use it anyway.
Your answer
Follow this Question
Related Questions
OnCollisionEnter Collision not detected? 1 Answer
Get the script instance associated with a collider 1 Answer
Translate.transform problems (collision/Rigibody) 0 Answers
Why do Instantiated GameObjects Colliders only work on player i am controlling,nothing else? 2 Answers
Physics.SphereCastAll to get rigidbody's like OnCollisionEnter 3 Answers