- Home /
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...
Answer by Tetrad · Jul 14, 2010 at 07:56 AM
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.
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?
It only shows you items in the scene for components and gameobjects - everything else you have to drag in
Answer by JanZimmermann · Apr 01, 2013 at 05:56 PM
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
Your answer
Follow this Question
Related Questions
Storing and using weapons and objects 0 Answers
Combining Meshes? 1 Answer
Scripting a prefab to duplicate itself within a fixed radius 2 Answers
Bullet Instantiation 1 Answer