x


Prefab Instantiation

I have created a prefab cPrefab. I have declared a public GameObject gamePrefab in the script.

To make it visible, I dragged the prefab over to the gamePrefab displayed under the script section displayed in the inspector.

When I try to Instantiate, I get the error "the name "cPrefab" does not exist in the current context.

How do I make the prefab accessible so I can Instatiate it?

more ▼

asked Jun 26 '12 at 06:17 PM

gamecogk gravatar image

gamecogk
-5 1 2 3

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

1 answer: sort voted first

public GameObject ob; public Vector3 position; ... GameObject.Instantiate(ob,position); ...

You use variable names in scripts, not object names. Sounds like you're trying to Instantiate(cPrefab) when your script has nothing called 'cPrefab'.

more ▼

answered Jun 26 '12 at 06:27 PM

Loius gravatar image

Loius
10.9k 1 12 43

(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:

x1725
x1285

asked: Jun 26 '12 at 06:17 PM

Seen: 342 times

Last Updated: Jun 26 '12 at 06:27 PM