Hi everyone, ive got stuck on a piece for the game im working on
first of all the problomatic code
part 1
function OnGUI ()
{
if(isincombat)
{
GUI.Label (Rect (700, 10, 500, 300), "" + enemymonster.name);
GUI.Label (Rect (700, 30, 500, 300), "" + enemymonster.baseHP + "/" + enemymonster.currHP);
GUI.DrawTexture (Rect(900, 130, 128, 128), enemymonster.image);
if(spawned == false)
{
Instantiate(enemymonster.gamemodel,enemymonsterspawn.transform.position,enemymonsterspawn.transform.rotation);
spawned = true;
}
GUI.Label (Rect (10, 10, 500, 300), "" + equippedmonster.name);
GUI.Label (Rect (10, 30, 500, 300), "" + equippedmonster.baseHP + "/" + equippedmonster.currHP);
GUI.DrawTexture (Rect(70, 10, 128, 128), equippedmonster.image);
GUI.Label (Rect (10, 50, 500, 300),"Level " + equippedmonster.level + " XP " + equippedmonster.curXp + " / " + equippedmonster.maxXp);
if(spawned2 == false)
{
Instantiate(equippedmonster.gamemodel,mymonsterspawn.transform.position,mymonsterspawn.transform.rotation);
spawned2 = true;
}
if (!spawned)
{
Destroy(GameObject.Find(enemymonster.name + "(Clone)"));
}
if (!spawned2)
{
Destroy(GameObject.Find(equippedmonster.name + "(Clone)"));
}
if (!displaygui) return;
if(monstersub)
{ for(var k=0; k < 6; k++)
{
if(GUI.Button(Rect(700,150 + (k * 50),100, 30),"" + mymonsters[k].name))
{
Destroy(GameObject.Find(equippedmonster.name + "(Clone)"));
equippedmonster = mymonsters[k];
if(spawned2)
{
Instantiate(equippedmonster.gamemodel,mymonsterspawn.transform.position,mymonsterspawn.transform.rotation);
}
}
}
now the problem im facing is that way im despawning the monsters by finding by name + clone is fine but when the players equipped monster is has the same name as the enemy monster there is no way of telling which one to destroy and it generally destroys the wrong one.
Oh the monsters are an array containing the gamemodels stats etc
hope im making sense and would appreciate any help or maybe a better way of placing and destroying prefabs runtime.