x


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

more ▼

asked May 17 '10 at 10:12 AM

TheMPC gravatar image

TheMPC
93 4 4 12

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered May 18 '10 at 02:53 PM

TheMPC gravatar image

TheMPC
93 4 4 12

(comments are locked)
10|3000 characters needed characters left

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) }

more ▼

answered May 17 '10 at 11:55 AM

Fuller gravatar image

Fuller
63 2 3 9

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5051
x3442
x1249

asked: May 17 '10 at 10:12 AM

Seen: 2513 times

Last Updated: May 18 '10 at 02:46 PM