IEnumerator MoveToPoint() { while (Vector3.Distance(elevatorTargetPosition.position, transform.position) > closeToPoint) { transform.position = Vector3.MoveTowards(transform.position, elevatorTargetPosition.position, elevatorSpeed * Time.deltaTime); //this will be on the object if it has a CubeMotor so no null check. yield return(null); } _player.transform.SetParent(null, true); _controller.IsKinematic(false); _controller.UseGravity(true); _cubeMotor.SetMovementActive(true); }
void Start() { _player = TheCubeGameManager.player; _rb = GetComponent <Rigidbody>(); if (_player != null && elevatorTargetPosition != null) { _cubeMotor = _player.GetComponent <CubeMotor>(); if (_cubeMotor != null) { _cubeMotor.SetMovementActive(false); } if (pointToMovePlayerTo != null) { _controller = _player.GetComponent <CubeController>(); _controller.IsKinematic(true); _controller.UseGravity(false); _player.transform.SetParent(transform); _player.transform.position = pointToMovePlayerTo.position; } StartCoroutine("MoveToPoint"); } }