private void CheckIfCloseToPlayers() { bool tooFarFromPlayers = true; foreach (var position in pigRoot.activePlayers) { if (Vector3.Distance(transform.position, position.position) < tooFarDistance) { tooFarFromPlayers = false; } } if (tooFarFromPlayers) { pigRoot.Kill(); } }
public void TakeDamage(float damage) { if (!dead) { currentHealth -= damage; if (currentHealth <= 0) { dead = true; // print("died"); GameManager.Instance.pigsKilled++; //audioSource.SetActive(true); //audioSource.transform.SetParent(null); Instantiate(audioSource, transform.position, transform.rotation); pigRoot.Kill(); } } }