Trying to use classes inside scripts to display mutliple objects.
They seem to create successfully although only the last one displays on screen, using GUI Functios for this currently.
I’m stuck as to why i only see the last invader on screen and the others simply don’t appear.
Did some testing with Debug.Log and they all seem to be crated okay. Seems to be a sticking block for me
////////////////////////////////////////////////////////////////////////////////
//Global declarations
static var MAX_ENEMIES = 40;
var tex_enemy:Texture2D;
// SPRITE CLASS START
class CSprite{
var mytexture:Texture2D;
var x =0.0f;
var y= 0.0f;
var xspeed = 0;
var yspeed = 0;
var alive =1;
function CSprite(){
}
function Init(inx, iny, inalive){
mytexture = Resources.Load("invader");
x = inx;
y = iny;
alive = inalive;
}
function Display(){
if (alive == 1){
GUI.DrawTexture(Rect(x,y,8,8),mytexture);
}
}
}
// SPRITE CLASS END
static var enemies = new Array();
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//Inside Start
tex_enemy=Resources.Load("invader");
var tempenemy = new CSprite();
tempenemy.Init(100,100,1);
tempenemy.mytexture = tex_enemy;
for (i=0; i<MAX_ENEMIES; i++){
enemies.push(tempenemy);
enemies_.Init((i*16), 100, 1);_
enemies*.mytexture = tex_enemy;
_ }_
_////////////////////////////////////////////////////////////////////////////////*_
////////////////////////////////////////////////////////////////////////////////
//Inside ONGui
* for (i=0; i<MAX_ENEMIES; i++){
_ enemies.Display();
}*_
*//////////////////////////////////////////////////////////////////////////////// *