private void OnTriggerEnter(Collider other) { // Pings trash on radar if (other.tag == "Trash") { // If the object has been already detected within half rotation of the sweep then skip if (!colliders.Contains(other)) { RadarPing ping = Instantiate(radarPing, other.transform.position, Quaternion.Euler(90, 0, 0)).GetComponent <RadarPing>(); ping.transform.localScale = new Vector3(5, 5, 5); ping.transform.parent = radarPings.transform; colliders.Add(other); } } // Pings dock on radar if (other.tag == "Dock") { // If the object has been already detected within half rotation of the sweep then skip if (!colliders.Contains(other)) { RadarPing ping = Instantiate(radarPing, new Vector3(other.transform.position.x, 0, other.transform.position.z), Quaternion.Euler(90, 0, 0)).GetComponent <RadarPing>(); ping.SetColor(new Color(0, 1, 1, 1)); ping.transform.localScale = new Vector3(25, 25, 25); ping.transform.parent = radarPings.transform; colliders.Add(other); } } // Pings animal on radar if (other.tag == "Animal") { if (!colliders.Contains(other)) { RadarPing ping = Instantiate(radarPing, new Vector3(other.transform.position.x, 0, other.transform.position.z), Quaternion.Euler(90, 0, 0)).GetComponent <RadarPing>(); ping.SetColor(new Color(1, 1, 0, 1)); ping.transform.localScale = new Vector3(30, 30, 30); ping.transform.parent = radarPings.transform; colliders.Add(other); } } if (other.tag == "Obstacle") { if (!colliders.Contains(other)) { RadarPing ping = Instantiate(radarPing, new Vector3(other.transform.position.x, 0, other.transform.position.z), Quaternion.Euler(90, 0, 0)).GetComponent <RadarPing>(); ping.SetColor(new Color(1, 0, 0, 1)); ping.transform.localScale = new Vector3(15, 15, 15); ping.transform.parent = radarPings.transform; colliders.Add(other); } } }
void UpdateRadarDetection() { RaycastHit[] hits = Physics.SphereCastAll(startPosition - (transform.forward * range), range, transform.forward, 10 * range, layerToDetect); if (hits.Length > 0) { foreach (var hit in hits) { if (!alreadyPingedColliderList.Contains(hit.collider)) { alreadyPingedColliderList.Add(hit.collider); Transform radarPingTransform = Instantiate(pfRadarPing, new Vector3(hit.collider.transform.position.x, hit.collider.transform.position.y, hit.collider.transform.position.z - (hit.collider.transform.localScale.z / 2) - 1.1f), Quaternion.identity); RadarPing radarPing = radarPingTransform.GetComponent <RadarPing>(); if (radarPing) { radarPing.SetColor(Color.white); } } } } }