GameObject instance =
Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
Instantiate is a GameObject function but why can I excute the function directly like:
Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity)
What is the function of “GameObject instance =” and “as GameObject”?
Instantiate is a function of Object.
Component inherits from Object.
Behaviour inherits from Component.
MonoBehaviour inherits from Behaviour.
And your script inherits from MonoBehaviour. So you can call Instantiate.
"GameObject instance = " declares a variable called “instance” of type GameObject, and assigns its value to whatever is on the right hand side of that expression.
“as GameObject” is an explicit cast of a value to the GameObject type.