The following code will create/spawn/instantiate an instance of a prefab you have referenced.
Instantiate with a reference to the instance
Sometimes you want to operate on an object immediately after you have instantiated it.
Same as above, but stores the instance in a local variable instead of a member variable.
Instantiate with a reference to a Component on the instance
Instantiate was updated by Unity to understand what type the object is you are trying to instantiate.
In Visual Studio, you can hover over Instantiate with the mouse cursor and a tooltip will show you the Type it’s trying to return.
Before this feature, a hard or soft Cast was required. See the following example:
Notes
Instantiate was updated at some point to return the Type of the object you are trying to instantiate, so no casting is required. If using an older version, it is recommened to soft cast to the type you desire, otherwise it will return you an Object.