So for example I have characters with this script:
public class Player : MonoBehaviour, IEntity {
private int _speed = 5; //(Different characters have different speeds)
public int Speed { get{return _speed;} set{_speed = value;} }
}
with this interface:
public interface IEntity{
int Speed { get; set; }
}
And I want to order an array of all players. I researched and came up with this function but it doesn’t work. Can anyone point me in the right direction? thanks.
.
.
.
var sortedArray = _allEntities.OrderBy(go => CompareCondition(go)).ToArray();
}
int CompareCondition(GameObject go)
{
var property = (IEntity)go.GetComponent(typeof(IEntity));
return property.Speed;
}