Hello,
I have GameObjects in an array found by a tag in a certain distance. I have an enum of conditions:
public enum Condition
{
Critical = 10,
Moderate = 25,
Barely = 50
}
I want to sort them by most important ones e.g.
Barely
Barely
Moderate
Critical
and after that do something with them from 1st to last. How can I achieve that? Would appreciate if anyone would explain the best approach for this, here is the code:
protected void CheckForCloseBodies(string tag, float minimumDistance)
{
GameObject[] goWithTag = GameObject.FindGameObjectsWithTag(tag);
var newCurrentHealth = 0.0f;
for (int i = 0; i < goWithTag.Length; ++i)
{
var bodyDamageHandler = goWithTag*.GetComponent<vp_DamageHandler>(); // Dead Bodys*
var bodysCondition = goWithTag*.GetComponent();*
var convertedHealth = bodysCondition.checkScavangeCondition();
if (Vector3.Distance(transform.position, goWithTag*.transform.position) <= minimumDistance)*
{
if (transform.position != goWithTag*.transform.position)*
{
if (bodyDamageHandler.IsDead == true)
{
if (bodysCondition.AbleToScavenge == true)
{
newCurrentHealth = PlayerDamageComponent.CurrentHealth + convertedHealth;
if (goWithTag.Length > 1)
{
// HERE IT SHOULD SORT THEM
}
else
{
if (newCurrentHealth <= PlayerDamageComponent.MaxHealth)
{
Debug.Log(PlayerDamageComponent.CurrentHealth = newCurrentHealth);
bodysCondition.scavangableHealth = 0.0f;
}
else
{
if (!isFullHealth)
{
bodysCondition.scavangableHealth = newCurrentHealth - PlayerDamageComponent.MaxHealth;
newCurrentHealth = newCurrentHealth - bodysCondition.scavangableHealth;
}
}
}
}
}
}
}
}
}
Thank you