void Update() { var current = river.GetCurrent(transform.position.y); transform.position += (Vector3)current * 2f * Time.deltaTime; var cameraSize = Camera.main.orthographicSize; var cameraTop = cameraPosition.position.y + cameraSize; var cameraBottom = cameraPosition.position.y - cameraSize; if (transform.position.y > cameraTop + 2f) { var y = cameraBottom; var x = Random.Range(river.GetBank(y, true), river.GetBank(y, false)); MoveTo(new Vector3(x, y, transform.position.z)); } else if (transform.position.y < cameraBottom - 2f) { var y = cameraTop; var x = Random.Range(river.GetBank(y, true), river.GetBank(y, false)); MoveTo(new Vector3(x, y, transform.position.z)); } }