public PlayerUnit GetPlayerUnitPrefab( PlayerUnit.UnitType type ) { PlayerUnit result = null; // For loop for(int i = 0; i < _playerUnitPrefabs.Length; ++i ) { if(_playerUnitPrefabs[i].Type == type) { result = _playerUnitPrefabs[i]; break; } } // Foreach loop //foreach(PlayerUnit playerUnit in _playerUnitPrefabs) //{ // if(playerUnit.Type == type) // { // result = playerUnit; // break; // } //} return result; // Linq version //return _playerUnitPrefabs. // FirstOrDefault ( prefab => prefab.Type == type ); }
private void OnValueChanged(int index) { string selectionText = _dropdown.options[index].text; SelectedUnitType = (PlayerUnit.UnitType) Enum.Parse(typeof(PlayerUnit.UnitType), selectionText); }