Hello all,
I have this code:
var laser : Transform;
var fireRate : float = 0.5f;
private var nextFire : float = 0.0;
var speed : float = 1.0;
private var bottom : Vector3 = Vector3(0, -1, 0);
function Update() {
if (Input.GetButton("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
var clone : GameObject = Instantiate(laser, transform.position, transform.rotation) as GameObject;
clone.transform.Translate(bottom * speed * Time.deltaTime);
}
}
I get an error at the last line “object reference not set to an instance of an object”. I have no idea why.
By the way, I have seen some tutorials using Rigidbody instead of transform and gameobject, but I guess that’s because the bullet is meant to be “invisible”. I want mine to be a normal object.