|
How do you instantiate a Prefab in C#? I've been doing it by loading a resource and then casting it into a UnityEngine.Object: UnityEngine.Object MyPrefab = Resources.Load("MyPrefabl"); Is there a way to do it without using the Resources.Load? Thanks!
(comments are locked)
|
|
define a public variable of type GameObject in your component (script) and then in the inspector drag a prefab on it and you can instantiate it.
when you attach this small script to a gameObject it will add script1 component to it's inspector and the script1 component has a slot called ball. you should drag a prefab to it and then the code will instantiated that dragged prefab. Thanks! Works good.
May 05 '10 at 05:55 PM
Jason Jolley
nothing special!
May 06 '10 at 08:54 AM
Ashkan_gc
and I suppose this is how you can instantiate the prefab all within the script only, without draggin it in the inspector: http://answers.unity3d.com/questions/17425/instantiate-prefab-wihtout-dragging-prefab-into-gameobject-script
Oct 19 '10 at 12:19 PM
Cawas
Thanks. It is fully right answer. The other way to Find the object somewhere in scene... but it is not useful IMHO.
Jun 25 '12 at 09:16 PM
shaman4d
(comments are locked)
|
Thanks! I Appreciate the help :)
May 05 '10 at 05:56 PM
Jason Jolley
(comments are locked)
|
|
Use Prefab in your Game Here is the tutorial for that . http://lnkd.in/J6ufVr . Here is demo and code for Prefab instantiate so download and try to undestand i hope u will get the solution ..
(comments are locked)
|

yeah but that object "ball" becomes it self when instantiated and not prefab
and thanks for your Question now I know how to Instantiate Object so it has Prefab in it and not it self