This is a feature of the C# programming language called an explicit cast.
When you have a reference of a type of a base class or interface, but you are sure that the object it points to is of a certain more specific sub-class, then you can use it to convert that reference to a reference of the more specific class.
In this particular example, a Renderer
is a sub-class of Component
. Every Renderer
is a Component
but not every Component
is a Renderer
. So when you have a reference of type Component
, then you can only use those methods and properties which all components have in common. The component might actually be a renderer, but the C# compiler can't be 100% sure about that just from this sourcecode. So it won't let you use any methods or properties of that object which are part of the Renderer
class.
However, in this particular case you as the programmer can be pretty sure that this Component b
is not any component but a Renderer
. After all, you acquired it through the method GetComponentsInChildren(typeof(Renderer))
. So you can actually "promote" that reference from Component
to Renderer
by writing (Renderer)b
. But should you be wrong about that and due to some bug in your code b
is actually a different component, then this operation will throw an InvalidCastException
at runtime.
But, as Nikaas pointed out, this code example is very outdated. It's from over 10 years ago. In more modern versions of Unity you would use GetComponentsInChildren<Renderer>()
instead, because that way you get the result set already cast into Renderer
s and not as Component
s.
Unity changed a lot in the past couple years. But unfortunately, information from the early years is still abundant around the Internet. So when you want to learn Unity you are well-advised to look at the publication dates of what you are reading/viewing/hearing and take any advise older than a couple years with a grain of salt.