private void OnCollisionEnter(Collision col) { if (!col.gameObject.CompareTag("Bullet") && !col.gameObject.transform.root.CompareTag("Player")) { GameObject explosionClone = Instantiate(explosion, transform.position, transform.rotation); explosionClone.SendMessage("PlaySound", explosionSound); Destroy(explosionClone, 15f); GameObject[] enemies = AreaSearch.FindAllInRadiusWithTag(transform.position, blastRadius, "Enemy"); GameObject[] players = AreaSearch.FindAllInRadiusWithTag(transform.position, blastRadius / 2, "Player"); showHitmarker = false; foreach (GameObject i in enemies) { if (AreaSearch.CheckInLineOfSight(transform.position, i)) { health = i.transform.gameObject.GetComponent <HealthSinglePlayer>(); health.TakeDamage((int)(damage / (Vector3.Distance(transform.position, i.transform.position)) / 2)); showHitmarker = true; } } foreach (GameObject i in players) { if (AreaSearch.CheckInLineOfSight(transform.position, i)) { health = i.transform.gameObject.GetComponent <HealthSinglePlayer>(); health.TakeDamage((damage / 3) / (Vector3.Distance(transform.position, i.transform.position)) / 2); } } if (showHitmarker) { playerProperties.ShowHitmarker(false, .2f); } Destroy(gameObject); } }
public void TriggerPlayerDetection() { if (!willWander) { willWander = true; return; } if (shootingRangeMode) { return; } GameObject[] closePlayers = AreaSearch.FindAllInRadiusWithTag(transform.position, playerAgroRadius, "Player"); Debug.Log("Number of close players: " + closePlayers.Length); bool[] isInLineOfSight = AreaSearch.CheckInLineOfSight(transform.position, closePlayers); for (int i = 0; i < isInLineOfSight.Length; i++) { if (isInLineOfSight[i]) { SetPlayerDetected(true); SetPlayerPosition(closePlayers[i].transform); for (int j = 0; j < detectionObjects.Count; j++) { detectionObjects[j].playerDetected = true; detectionObjects[j].playerProperties = closePlayers[i].transform.GetComponent <PlayerProperties>(); } Debug.Log(closePlayers[i] + " is in line of sight"); break; } else { Debug.Log(closePlayers[i] + " is not in line of sight"); } } }
IEnumerator TimedExplosion() { yield return(new WaitForSeconds(explosionTimer)); GameObject explosionClone = Instantiate(explosion, transform.position, Quaternion.LookRotation(transform.up)); explosionClone.SendMessage("PlaySound", explosionSound); Destroy(explosionClone, 2f); GameObject[] enemies = AreaSearch.FindAllInRadiusWithTag(transform.position, blastRadius, "Enemy"); bool[] lineOfSight = new bool[enemies.Length]; if (enemies != null) { lineOfSight = AreaSearch.CheckInLineOfSight(transform.position, enemies); } showHitmarker = false; int count = 0; foreach (GameObject i in enemies) { if (lineOfSight[count]) { health = i.transform.gameObject.GetComponent <HealthSinglePlayer>(); health.TakeDamage((int)((damage * 7.5) / Vector3.Distance(transform.position, i.transform.position))); showHitmarker = true; } count++; } if (showHitmarker) { playerProperties.ShowHitmarker(false, .2f); } Destroy(gameObject); yield return(null); }