How to correctly convert Object to GameObject

  1. In my UnityScript code I need load a prefab. Currently, I’m doing this as

var prefab : GameObject = Resource.Load("MyPrefab")

which gives me a warning about implicit conversions from Object to GameObject. I need it to be a GameObject because I need to position it based on its renderer.bounds.size. How can I get rid of this warning?

  1. When instantiating with Object.Instantiate, is it safe for me to convert the returned Object to GameObject? I need to modify some of its attributes when placing it in the world.

var prefab : GameObject = Resource.Load(“MyPrefab”)as GameObject;

That should solve all the problems. You can alter it however you’d like AFTER instantiating it

var myGO=Instantiate(prefab,,Quaternion.identity);

Or you could say

var myGO=Instantiate(Resource.Load("MyPrefab"),,Quaternion.identity)as GameObject;