x


Instantiating an Object...

Hey guys,

I'm working through the Unity Game Development Essentials textbook and want to add in a trap that steals the player's batteries if they come into contact with it.

I have the trap deducting a charge on collision, but I'm stuck on the instantiation of objects.

I want to instantiate one of my prefabs and have it fly out of the player as it does so (so they can follow it and see where it landed)

I'm using the code from here: http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html

But I'm not sure how to define a prefab in the variable.

Second question is, does my prefab need a rigidbody for me to 'launch' it out of the player?

Thanks.

more ▼

asked Jul 14 '10 at 12:54 AM

Troy gravatar image

Troy
32 8 8 9

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

1 answer: sort voted first

If you want to define a prefab, write the following line at the top of your script:

var prefabToCreate : GameObject;
more ▼

answered Jul 14 '10 at 01:15 AM

Daniel 6 gravatar image

Daniel 6
541 2 4 17

so the variable name is the prefab I want to create?

Jul 14 '10 at 01:32 AM Troy

oh right, i'd been forgetting to define it in the inspector, thanks!

Jul 14 '10 at 01:40 AM Troy
(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:

x3465
x2097
x1260
x112

asked: Jul 14 '10 at 12:54 AM

Seen: 686 times

Last Updated: Jul 14 '10 at 12:54 AM