x


Cannot assign prefab in Inspector?

Hello, I'm following along with the Unity Game Development Essentials book and am up to chapter 6, I've declared a rigidbody prefab in the script that I want to instantiate, but I can't assign this in the inspector (it shows that there are no rigidbody prefabs...?), the only way I can define something is by having it in the scene, which does not work.

The code I am using is

var coconutObject : Rigidbody;

I have no idea what is going on here...

more ▼

asked Jul 14 '10 at 07:52 AM

Troy gravatar image

Troy
32 8 8 9

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

2 answers: sort voted first

That works fine for me assuming you drag the prefab from the project window into the inspector field. It won't show up on the drop down list, though.

more ▼

answered Jul 14 '10 at 07:56 AM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

Thanks, hadn't though of dragging and dropping! I'm so used to using the drop down menu... is there some reason why it has to be done this way?

Jul 14 '10 at 08:00 AM Troy

It only shows you items in the scene for components and gameobjects - everything else you have to drag in

Jul 14 '10 at 08:30 AM Mike 3
(comments are locked)
10|3000 characters needed characters left

Hi, same problem here.. I have to variables here in my Code I want to Assign one of the variable of type Rigidbody with a prefab. This Fails. On the second Variable of Type Transform this works Fine. (I try to use both Drag and Drop and the List)

public class ShootBullet : MonoBehaviour {


    public Rigidbody BulletPrefab;
    public Transform CylinderEnd;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
       if(Input.GetKeyDown(KeyCode.Space))
       {
         //var bullet = Instantiate(
       }

    }
}

Any Suggestions?

Thanks

Jan

more ▼

answered Apr 01 at 05:56 PM

JanZimmermann gravatar image

JanZimmermann
1

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

x3459
x1672
x1255
x1093

asked: Jul 14 '10 at 07:52 AM

Seen: 1706 times

Last Updated: Apr 01 at 05:56 PM