In lecture 97 (Unity 3D) we are to add a Rigidbody component to an enemy object on Start().
I messed about with this a little and came to the solution:
gameObject.AddComponent<Rigidbody>().useGravity = false;
With the idea to stop gravity at the moment the Rigidbody component is added. I tested it and it all seems to work as intended.
In the lecture itself though, the example went as follows:
Rigidbody rb = AddComponent<Rigidbody>();
rb.useGravity = false;
If both of these work (or I might be wrong), why use the second example and create more lines of code (he goes on to refactor the code into it’s own method), when it can be done within the same line of code?