private void Move() { //설정 속도에 따라 움직일 위치를 계산(MoveTowards) 이후 이동 transform.position = Vector2.MoveTowards(transform.position, targetPoint, moveSpeed * Time.deltaTime); //목적지에 도달했을 경우 버튼 입력 상황에 따라 목적지를 재계산하거나 멈춤 if (transform.position.Equals(targetPoint)) { RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, new Vector2()); foreach (RaycastHit2D hit in hits) { StairPoint stairPoint = hit.collider.gameObject.GetComponent <StairPoint>(); if (stairPoint != null) { Vector2 newPos = stairPoint.LinkedPoint; bool posConfirmed = false; while (!posConfirmed) { RaycastHit2D[] stairFrontHits = Physics2D.RaycastAll(newPos, new Vector2()); posConfirmed = true; foreach (RaycastHit2D stairFrontHit in stairFrontHits) { if (!stairFrontHit.collider.isTrigger) { posConfirmed = false; if (newPos.y > transform.position.y) { newPos += Vector2.up; } else { newPos += Vector2.down; } break; } } } if (stairPoint.IsToUpstair) { CurFloor += 1; } else { CurFloor -= 1; } Debug.Log(CurFloor); transform.position = newPos; break; } SecretPathController secretPath = hit.collider.gameObject.GetComponent <SecretPathController>(); Vector3 linkedPos; if (secretPath != null && (linkedPos = secretPath.GetLinkedPos()).z == 0f) { transform.position = linkedPos; break; } } if (curDirection != EMoveDirection.Stop) { SetNewTargetPoint(); } else { isMoving = false; SetAnimationProperty(); } } return; }
public void Link(SecretPathController path) { linkedPath = path; }