private void OnCollisionEnter(Collision other) { if (other.gameObject.CompareTag("Bounds")) { OnOutOfBounds?.Invoke(this); Destroy(gameObject); } }
private void FixedUpdate() { if (autoMove == true && canMove == true) { movable.MoveRight(); } if (gameObject.transform.position.x >= xBound) { OnOutOfBounds?.Invoke(); } }
private void OnTriggerExit2D(Collider2D other) { if (other.tag == "Player" || other.tag == "Enemy") { if (OnOutOfBounds != null) OnOutOfBounds.Invoke(other.GetComponent<HealthComponent>()); } else if (other.transform.parent.parent == null) { if (OnOutOfBoundsItem != null) OnOutOfBoundsItem.Invoke(other.transform); } }
private void OnTriggerExit(Collider other) { if (other.CompareTag("bounds")) { Vector3 bounds = other.GetComponent <Collider>().bounds.size; Vector3 otherPos = other.transform.position; bool wrapped = false; //If exit right if (transform.position.x > otherPos.x + (bounds.x / 2)) { transform.position = new Vector3(otherPos.x - (bounds.x / 2), transform.position.y, transform.position.z); wrapped = true; } else { //if exit left if (transform.position.x < otherPos.x - (bounds.x / 2)) { transform.position = new Vector3(otherPos.x + (bounds.x / 2), transform.position.y, transform.position.z); wrapped = true; } } if (transform.position.z > otherPos.z + (bounds.z / 2)) { //if exit forward transform.position = new Vector3( transform.position.x, transform.position.y, otherPos.z - (bounds.z / 2)); wrapped = true; } else { //if exit backwards if (transform.position.z < otherPos.z - (bounds.z / 2)) { transform.position = new Vector3( transform.position.x, transform.position.y, otherPos.z + (bounds.z / 2)); wrapped = true; } } //if exited bounds but none of the above //(they steer up and down to avoid bottom and top, but just in case) if (!wrapped) { Transform sP = BoidsManager.GetRandomSpawnPoint(); //Respawn this.transform.position = sP.position; this.transform.rotation = sP.rotation; #if DEBUG OobCount++; Debug.LogWarning( "Out of bound count: " + OobCount + " - total time: " + Time.time, gameObject); #endif } //invoke out of bounds event if not null onOutOfBounds?.Invoke(); } }
public void OutOfBounds() { OnOutOfBounds?.Invoke(); }