I’m currently getting a problem with using instantiate to fire a projectile, it works fine in the editor but not once built as webplayer or standalone.
The error I’m getting in the output log is:
**NullReferenceException: Object reference not set to an instance of an object
at Elements.Update () [0x00000] in :0
(Filename: Line: -1)**
I have had a look at other examples with this happening but had no luck with implementing it into my code. Any help with sorting this out would be appreciated.
#pragma strict
static var element : int = 1;
var bulletfire : Rigidbody;
var bulletice : Rigidbody;
var power : float = 1500;
var damage : float = 100;
var bulletcount : int = 10000;
var gunshot: AudioClip;
var allowfire : int = 1;
function Start () {
bulletcount = bulletcount;
}
function checkgun () {
yield WaitForSeconds (0.5);
allowfire = 1;
}
function Update () {
if (Input.GetKeyDown ("1")){
element = 1;
}
if (Input.GetButton("Fire1")&& (allowfire == 1) && bulletcount && (element == 1)){
allowfire = 0;
audio.PlayOneShot(gunshot);
var instance1: Rigidbody = Instantiate(bulletfire, transform.position, transform.rotation) as Rigidbody;
var fwd1: Vector3 = transform.TransformDirection(Vector3.forward);
instance1.AddForce(fwd1 * power);
bulletcount --;
checkgun();
}
if (Input.GetKeyDown ("2")){
element = 2;
}
}