- Home /
How to add Circle Collider 2D in script
I was wondering if there is a way to instantiate a circle collider 2d in script. I wanted to add a circle collider to make each point i score count twice. Is there any way to add a circle collider based on a conditional statement and specify the size?
Answer by robertbu · Oct 26, 2014 at 03:27 PM
This is just an AddComponent():
#pragma strict
function Start() {
var cc : CircleCollider2D = gameObject.AddComponent(CircleCollider2D);
cc.radius = 4.0f;
}
Note historically, Unity did not allow you to add more than one copy of the same collider to a game object, but running a quick test, I see now it is allowed (both 2D and 3D). Not sure when it changed. I'm running 4.6.
Your answer
Follow this Question
Related Questions
How to diable colliders after scoring point 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Terrain with lots of objects 1 Answer
2 Colliders on 1 gameobject 2 Answers