Help with my Arrow Fire Script
Hi, im new to c# programing in unity and I have been trying to create a primative arrow fire script but no matter how hard I try I keep get this error after shooting an arrow:
NullReferenceException: Object reference not set to an instance of an object Arrow_Fire.Update () (at Assets/Scripts/Arrow_Fire.cs:15)
Here is the code too so if you have any suggestions it would help greatly (:
using UnityEngine; using System.Collections;
public class Arrow_Fire : MonoBehaviour {
public Rigidbody arrow;
public int speed = 20;
void Update () {
if (Input.GetButtonDown("Fire1")) {
Rigidbody arrowClone = Instantiate(arrow, transform.position, transform.rotation) as Rigidbody;
arrowClone.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
}
}
}
Please format your code. If you don't know how watch the tutorial video on the right
Answer by ncortiz · Apr 06, 2016 at 05:57 PM
That probably happens because you didn't assign an arrow prefab to the script in the properties.
Your answer
Follow this Question
Related Questions
My gun reloading dont work,can i please get help. 2 Answers
Shotguns with raycasts 0 Answers
Help me with health script 2 Answers
Error CS8025: Parsing Error 3 Answers
how to add shoot cooldown 1 Answer