public List <string> Report() { HashSet <Interesting> seen = new HashSet <Interesting>(); for (int i = 0; i < numRays; i++) { float offset = (i - (numRays / 2)) / (float)numRays; float angle = offset * fieldOfView * 2; Vector3 rayDir = Quaternion.AngleAxis(angle, Vector3.up) * transform.forward; Ray ray = new Ray(transform.position, rayDir); RaycastHit hit; if (Physics.Raycast(ray, out hit, viewDistance)) { Debug.DrawLine(transform.position, transform.position + rayDir * viewDistance, Color.red); var interesting = hit.collider.GetComponent <Interesting>(); if (interesting) { var theirHealth = hit.collider.GetComponent <Health>(); if (health != null) { seen.Add(interesting); } } if (hit.collider.GetComponent <SoldierInfo>()) { var theirHealth = hit.collider.GetComponent <Health>(); if (health != null) { if (theirHealth.isDead) { Debug.Log("I've seen a dead soldier"); Animator theirAnim; theirAnim = hit.collider.GetComponentInChildren <Animator>(); theirAnim.SetBool("isDowned", true); theirAnim.SetBool("isMIA", false); } } } } else { Debug.DrawLine(transform.position, transform.position + rayDir * viewDistance); } } var counts = seen.GroupBy(item => item.Type).Select(group => new { Type = group.Key, Count = group.Count(), Priority = group.ElementAt(0).priority, FirstPos = group.ElementAt(0).transform.position }); counts = counts.OrderByDescending(item => item.Priority); var reports = new List <string>(); foreach (var count in counts) { if (reports.Count > 0) { if (Random.value < additionalReportChance || reports.Count >= maxReports) { break; } } if (health.isDead) { reports.Add(Garble(Garble(Garble(Garble(Garble(Garble("AAARARRRRRRGGGGHHHHH!!!!!!!!!"))))))); } else { string report; if (count.Count == 1) { string gridPos = grid.CoordsToGridString(grid.WorldCoordsToGrid(count.FirstPos)); report = transform.name + " saw a " + count.Type + " at " + gridPos; } else { report = transform.name + " saw " + count.Count + " " + count.Type; } reports.Add(Garble(report)); } } uiioMan.Report(reports, GetComponent <SoldierInfo>().name); return(reports); }