Skip to main content

Posts

Showing posts with the label Instantiate

Loading Project Assets Through A Script (dynamically)

To do so, you first need to start by creating a new folder and naming it "Resources" You put whatever you want to load in the script in the folder, textures, prefabs, all that stuff. So if you want to Instantiate a prefab, you would simply put this in the code. var boat : GameObject = (Resources.Load("Boat")); Instantiate(boat, location, rotation); Simple right? If you want to get something out of a folder in the resources folder you just say: var smallBoat : GameObject = (Resources.Load("folder name/Small Boat")); Ta da. Easy. Read more at Unity's scripting Reference here

How to Instantiate!

When you instantiate something, you clone it, put it in the position you want, and the rotation you want. A very simple command. Done like this: function Update(){     Instantiate(transform, transform.position, transform.rotation); } So basically what this script does is clones what ever the script is attached to at the position of the object, and its rotation. Not really the best thing. Better yet it's in the Update function, which is being called every frame thats rendered, so thats allot of clones ha..