I need multiple colliders on a gameObject.
I would just use AddComponent(), but there’s got to be around 20 colliders, which means 20 lines of copy&paste code, the name of the collider being the only thing changed.
So, how to use a for() for this?
And is it even possible?
for(int i = 0; i <= 20; i++){
//Add a collider of name Collider-i or similar
}
You can’t have more than one of the same type of collider attached to an object. You can have, say, a box collider and a capsule collider, but they will both behave exactly the same way.
I suggesy tou rethink your problem - why are you trying to programmatically create 20 colliders?
Once again, after some research I solved the problem and post an answer to those who may of encountered the same problem:
Dictionary<int, BoxCollider> yourColliders= new Dictionary<int, BoxCollider>();
for(int i = 0; i <= Amount of colliders you need; i++){
yourColliders.Add(i, this.gameObject.AddComponent("BoxCollider") as BoxCollider);
}
After this you have a dictionary of box colliders, if you want to change their size, etc. you refer to them as yourColliders[7] and so on.