- Home /
Question by
BawsAnimations · Dec 09, 2012 at 08:54 PM ·
instantiatenullreferenceexceptionbulletshoot
Shooting Script Instantiate Problems. Help?
I am trying to make a FPS. Everything works fine except my Instantiating script. I have tried various Instantiating scripts but it always comes down to the same error. NullRefenceException.
Here is the script. Can anyone fix it and tell me what's wrong? (Using Unity3, not 4) private var nextFire : float = 1.5;
function Start()
{
ammo = 31;
}
function Update()
{
if(Input.GetButtonDown("Fire1")&&Time.time > nextFire)
{
if(ammo > 0)
{
Fire();
}
else {
return;
}
}
if(Input.GetKeyUp("r"))
{
if (emptyClip)
Reload();
Debug.Log("reloading");
}
if (ammo <= 0)
{
emptyClip = true;
}
else {
emptyClip = false;
}
}
function Fire()
{
audio.PlayOneShot(gunfire);
nextFire = Time.deltaTime + firerate;
var Shot = Instantiate(TempBullet, transform.position, Quaternion.Identity);
TempBullet.rigidbody.AddForce(transform.forward * 1200);
ammo--;
Debug.Log("Shot");
}
function Reload()
{
audio.PlayOneShot(reload);
ammo = 30;
//animation.play for reload.
}
function OnGUI()
{
GUI.Label(Rect(100,70,Screen.height,50), "Ammo :" + ammo);
//correct Ammo : if necessary.
//Change coords later.
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Setting bullet instansiate direction? help? 1 Answer
Add force to Instantiated object. 4 Answers
Enemy Instantiating one bullet 3 Answers