Why do we need the as GameObject?
GameObject laser = Instantiate(laserPrefab, transform.position, Quaternion.identity) as GameObject;
It works for me without it - what’s the meaning of this reference?
Thanks
Why do we need the as GameObject?
GameObject laser = Instantiate(laserPrefab, transform.position, Quaternion.identity) as GameObject;
It works for me without it - what’s the meaning of this reference?
Thanks
Good question! Following for the answer.
Hi Niv, hi Jackie,
In past versions of Unity, casting was required. This was changed in one of the Unity 2017 versions (I think). Game developers who have been using Unity for years still cast with “as GameObject” out of habit. It’s not wrong to do that, just not required anymore.
Has your question been answered?
See also:
Thanks
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.