Hello I need help to optimize this code. I have a radar and it gets the enemies from a list and adds an image to their location to track them. I use Update to remove the images and LateUpdate to add the images. Is there any way I can do this without costing performance. I have a list of all the Enemies. I have a pool of over 40 images to use as tracking for the radar. Enemy is always moving. Any ideas?
private void Update()
{
if (statsView_Panel.activeInHierarchy)
{
if (showIndicators_Enemies)
{
if (!enemyListHolder.activeInHierarchy)
{
enemyListHolder.SetActive(true);
}
Remove_PositionIndicatorOnEnemies();
}
}
}
private void LateUpdate()
{
if (showIndicators_Enemies)
{
if (!enemyListHolder.activeInHierarchy)
{
enemyListHolder.SetActive(true);
}
Add_PositionIndicatorOnEnemies();
}
}
private void Add_PositionIndicatorOnEnemies()
{
// Do if ListHolder is Active
if (enemyListHolder.activeInHierarchy)
{
// Run if 1 or more Enemies
if (EnemiesManager.Count > 0)
{
// Check All Enemies
for (int i = 0; i < EnemiesManager.Count; i++)
{
// Check All Indicators
for (int s = 0; s < enemyIndicList.Count; s++)
{
// Choose Indicator that is not active *****BUG: Will Add All Deactivated Indicators to Active Enemies*****
if (enemyIndicList[s].gameObject.activeInHierarchy == false)
{
// Activate Indicator and Reposition
enemyIndicList[s].gameObject.SetActive(true);
Vector3 aLocatorPos;
aLocatorPos = theCam.WorldToScreenPoint(satManager.GetByIndex(i).transform.position);
aLocatorPos.z = 0;
enemyIndicList[s].transform.position = aLocatorPos;
// Break from Loop
break;
}
}
}
}
}
}
private void Remove_PositionIndicatorOnEnemies()
{
// Do if ListHolder is Active
if (enemyListHolder.activeInHierarchy)
{
// Run if 1 or more Enemies
if (EnemiesManager.Count > 0)
{
// Check All Indicators
for (int s = 0; s < enemyIndicList.Count; s++)
{
// Choose Indicator that is active
if (enemyIndicList[s].gameObject.activeInHierarchy == true)
{
// Deactivate Indicator
enemyIndicList[s].gameObject.SetActive(false);
}
}
}
}
}