public void InfectRandom(InfectionProps props) { var r = new Random(); var movingPersons = _persons.Where(x => x.Props.Speed > 0 && !x.IsRecovered).ToList(); var index = Mathf.FloorToInt((float)r.NextDouble() * movingPersons.Count); if (index >= 0 && index < movingPersons.Count - 1) { movingPersons[index].Infect(props); } }
public void Infect(InfectionProps infectionProps) { if (_state.IsInfected || _state.HasImmunity) { return; } _infectionProps = infectionProps; _state.TimeWhenInfected = Time.time; _state.IsInfected = true; updateView(); }