- Home /
Creating a Prefab - Javascript
Hello again,
This time im trying to create a prefab in javascript,
I created my Prefab in the project and want to place it on the screen by javascript. could someone please give me a piece of code that creates a new prefab (copy the one from the the project folder)?
Kind Regards, TheMPC
Answer by TheMPC · May 18, 2010 at 02:53 PM
Thank you for the first answer this gave me alot, but not the complete answer. After fooling around with your answer i figured out i had to do the following:
public var prefab:Transform
function Start() { Instantiate(prefab,new Vector3(0,0,0),transform.rotation); }
And link the prefab i want to create to the prefab var in the script.
nearly the same as the first answer, although i got alot of errors because i was using exacly what the answer stated.
Answer by Fuller · May 17, 2010 at 11:55 AM
Instantiate(transform,position,rotation)
where transform is the prefab.
For instance:
var player : Transform;
Function Start() { Instantiate(player,new Vector3(0,0,0),transform.rotation) }
Your answer