- Home /
Projectile Wont fire
Hello i have a javscript for handeling that a certain Ridigbody will fire when the left mouse button is clicked but it keeps giving me errors i removed the clicking part but it still says that the object reference is not set to an instance of object.
My script here.
var projectile : Rigidbody; var damage = 5;
function Update () {
Spawnpoint = transform.Find("/First Person Controller/Main Camera/Spawnpoint"); SpawnVector = Vector3(Spawnpoint.position.x, Spawnpoint.position.y, Spawnpoint.position.z); var clone : Rigidbody;
clone = Instantiate(projectile, SpawnVector, Spawnpoint.rotaition); clone.velocity = Spawnpoint.TransformDirection (SpawnVector.forward*20);
}
Would love if someone could help me with this.
Answer by BiG · Nov 29, 2012 at 10:19 PM
Your projectile has to be a prefab, and you have to "bind" that prefab to the variable "projectile". Once you assigned that script to the player, check the inspector of the player, than drag and drop the projectile's prefab onto the projectile's variable. I hope that's clear.
Answer by CevinWa · Nov 30, 2012 at 07:34 AM
It is a prefab and is set to be a rigidbody and i have dragged it to the variable but it still says this.
the object reference is not set to an instance of object.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084723im_/https://answers.unity.com/themes/thub/images/avi.jpg)