private IEnumerator co_BeAJerk() { while (true) { Debug.Log("Those jerks are changing their minds again..."); foreach (var vote in _votes) { int optionNumber = UnityEngine.Random.Range(0, _directions.Count + 1); if (optionNumber == _directions.Count) { Debug.Log($"\tThat jerk {vote.VoterID} couldn't decide on a direction to tilt in..."); vote.DirectionChoice = null; } else { Debug.Log($"\tThat jerk {vote.VoterID} is trying to tilt {Enum.GetName(typeof(ChoosableDirection), _directions[optionNumber])}!"); vote.DirectionChoice = _directions[optionNumber]; } } foreach (var vote in _votes) { InputVoteCollector.ApplyVote(vote); } yield return(new WaitForSeconds(JerkInterval)); } }
private void Update() { var input = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f); if (Mathf.Approximately(input.x, previousInput.x) && Mathf.Approximately(input.y, previousInput.y)) { //No change in input, don't waste time processing it again return; } if (Mathf.Approximately(input.magnitude, 0f)) { vote.DirectionChoice = null; } else { ChoosableDirection choice = default; var smallestAngle = 360f; foreach (var direction in InputVoteCollector.Choices.Keys) { var directionVector = InputVoteCollector.Choices[direction].vector; var angleBetween = Vector2.Angle(directionVector, input); if (angleBetween < smallestAngle) { choice = direction; smallestAngle = angleBetween; } } vote.DirectionChoice = choice; } InputVoteCollector.ApplyVote(vote); previousInput = input; }