- Home /
The question is answered, right answer was accepted
How to add colliders as objects into a public variable in the inspector?
Hi all, I am trying my hand at trying to make an Arkanoid Game. I am trying to get the paddle to work like how they do in most of these games, that is, the sides make the ball bounce at a different angle. The way I am trying to achieve this is by adding three child objects (PaddleLeft, PaddleMiddle and PaddleRight) to the parent Paddle game object and each child defines a collider for the three parts of the paddle (Left side, Middle and Right side). I've now created a public collider array for the paddle to accept each of these child objects into the array. However when I try to drag and drop the child objects into the collider array, it doesn't work. The inspector simply doesn't identify these objects as colliders I guess. So my question is how do I make the inspector identify these objects as colliders? Am I missing a component for the child objects that allows them to be identified as colliders? Or how do I create multiple colliders to a game object, each with its own behaviours?
Here is my paddle and on the side you can see the hierarchy. The Paddle has a paddle script attached to it which has an array of Colliders called colliders. I've defined the size as 3 and I am trying to add each of its child objects to it which the inspector (or Unity?) doesn't allow me to. Why?
In answer to your question, "Am I missing a component for the child objects that allows them to be identified as colliders?" - we can't tell as you're not showing us the make-up of the child objects. They would each need to have a collider component (of some sort) in order to be dragged onto your collider fields.
The three colliders you see on the paddle image are from each of those child objects. These are the middle and the left colliders.
Those are 2D colliders. Try making your array an array of Collider2D ins$$anonymous$$d of Collider
Answer by Incertam7 · Oct 29, 2017 at 01:10 AM
I'm answering here in case anybody else had the same problem and didn't check the comments section of the question.
As mentioned in the comments by @Bonfire-Boy , Collider[] is used to define an array of 3D colliders and not 2D ones. If you're using 2D colliders on your game object, create a Collider2D array.