- Home /
This question was
closed Jan 11, 2015 at 06:03 PM by
Graham-Dunnett for the following reason:
Duplicate Question
Question by
Boxvilel · Jan 11, 2015 at 06:02 PM ·
guinullreferenceexceptionloopfor
NullReferenceException in for-loop
So i'm still working on an doom-like fps and i wanted to implement some sort of gui to let the player know how many health is left and so on... but i simply won't work.
Here is the GUI Code: using UnityEngine; using System.Collections;
public class PlayerStatsGUI : MonoBehaviour
{
//Var initalization
public Transform PlayerStatsObj;
public StatsManager stats;
public Shoot shoot;
//Textures
public Texture2D knifes;
void Start()
{
stats = PlayerStatsObj.GetComponent<StatsManager>();
shoot = PlayerStatsObj.GetComponent<Shoot>();
}
void OnGUI()
{
//Health
//Ammo
for(int i = 0; i < shoot.currentAmmo; i++)
{
GUI.DrawTexture(new Rect((Screen.width / 2) + (i * 100), (Screen.height / 2 - 400), 100,100), knifes);
}
}
}
And this is the "ShootManagerScript":
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour
{
public int maxAmmo = 10;
public int currentAmmo = 10;
void Start()
{
}
}
I'm getting an NullReferenceException Error at line 25 in my GUI Script...
Thanks for any help or advice :)
Comment