public void teleport() { //top spawn point float yPos = 0f; //if player is on lower half, set y tele pos if (player.transform.position.y < -5) { yPos = -7.5f; } //find x tele position float teleX = xSpawnPoints; if (-7.5 < player.transform.position.x && player.transform.position.x < 7.5) { int random = rand.Next(1, 3); if (random == 1) { teleX *= -1; } } else if (player.transform.position.x >= 0) { teleX *= -1; } //teleport the boss to the correct position if (teleX > 0) { if (entityMovement.facingRight) { entityMovement.facingRight = false; entityMovement.Flip(); } entityMovement.facingRight = false; this.gameObject.transform.position = Vector2.Lerp(this.gameObject.transform.position, new Vector2(xSpawnPoints, yPos), 3); } else if (teleX <= 0) { if (!entityMovement.facingRight) { entityMovement.facingRight = true; entityMovement.Flip(); } entityMovement.facingRight = true; this.gameObject.transform.position = Vector2.Lerp(this.gameObject.transform.position, new Vector2(-xSpawnPoints, yPos), 3); } }
private void OnCollisionEnter2D(Collision2D coll) { //Hit side wall so reverse direction of movement if (coll.gameObject.CompareTag("SideWall")) { entityMovement.Flip(); } }