I am getting an error with this code saying variable prefabBullet isn’t defined. Explain.
"#pragma strict
function Start () {
}
var prefabBullet:Transform;
var shootForce:float;
function Update ()
{
if(Input.GetButton("Fire1"))
{
var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
}"
Use resource.load to load the prefab at runtime or assign it via the inspector. Prefabs reference outside resource gameObjects. If you call instantiate on an unitialized prefab reference, it will give this error.
In your initial explanation you said:
code saying variable prefabBullet isn’t defined
And then when you pasted the actual message it said:
You probably need to assign the prefabBullet variable of the Shoot script in the inspector.
Something not being “defined” is a very different error than something not having a value set. It’s best not to rephrase error messages when conveying them to others.
Assign a value to bulletPrefab in the inspector, and make sure the prefab you assigned has a rigidBody attached!