I’m still learning the correct way to use arrays in Unity and I have a basic question.
I would like to get an array of all weapons attached to my vehicle. I am using this code:
// The weapons attached to the vehicle
private RangedWeapon[] m_Weapons;
void Start()
{
// Get all weapons attached to the vehicle
GameObject Vehicle = transform.parent ? transform.parent.gameObject : null;
if(Vehicle)
{
m_Weapons = Vehicle.GetComponentsInChildren<RangedWeapon>();
}
}
Is this sufficient? Or do I need to allocate the m_Weapons array before assigning a value to it?
Thanks for any tips!