Question by
Oreboat · Jun 18, 2021 at 03:17 AM ·
array of gameobjects
deleting duplicate objects from array
So I'm trying to create a battle system inspired by FFXII and as such I need to track targets every frame, I got most of it working but I have an issue with it adding the same objects to the array every frame, is there any way to either delete the duplicates or prevent it from happening all together
here is the code
void Update()
{
Collider[] enemies = Physics.OverlapSphere(transform.position, Radius, layerMask);
foreach (Collider enemy in enemies)
{
Renderer E_Render = enemy.GetComponent<Renderer>() as Renderer;
if (E_Render.isVisible)
{
Debug.Log(enemy.name + "Is Visible and In range");
//Run the code
button = Instantiate(template, Content) as SelectButton;
button.enemySelect = enemy.GetComponent(typeof(Enemy)) as Enemy;
textMesh = button.GetComponentInChildren<TextMeshProUGUI>();
textMesh.SetText(enemy.name);
button.battle = this;
}
}
}
Comment
Your answer
