I am trying to create an array of GUITextures. I want the player’s lives to be shown in number of GUITextures.
Here is my script and I don’t understand why I can’t instantiate GUITextures. When I try to assign the texture it says that I have a null reference exception.
var score :int = 0;
var guiScore :GUIText;
var lives :int = 3;
var lifeShip :Texture;
var livesArray :GUITexture[];
function Start(){
guiScore.pixelOffset.x = -Screen.width/2.0;
guiScore.pixelOffset.y = Screen.height/2.0;
UpdateLives();
}
function UpdateLives(){
livesArray = new GUITexture[lives];
for(i = 0; i < lives; i++){
livesArray[i] = new GUITexture();
livesArray[i].texture = lifeShip;
livesArray[i].pixelInset = Rect(0, 50+i*129, lifeShip.width * Screen.width/1920, lifeShip.height * Screen.height/1200);
}
}
function AddToScore(value :int){
score += value;
guiScore.text = "Player Score: " + score;
}