2024/02/20

안석환·2024년 2월 20일

🧐기본 공부 내용


  1. 실행되고 있는 애니메이션의 현제 상태
  • 애니메이션의 스테이트 인포값을 받아와 실행되고 있는 애니메이션의 상태를 확인하고 실행 시점을 불러올 수 있다.


💾 코드

animator.GetCurrentAnimatorStateInfo(0).IsName("IsSpawning") && animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1.0f


  1. RectTransform.anchoredPosition
  • 유아이상의 트랜스폼을 변경할때는 고정위치값을 변경 시켜줘야한다.


💾 코드

Vector2 btnDestination = new Vector2(pos.anchoredPosition.x, pos.anchoredPosition.y - 150);
pos.anchoredPosition = Vector2.MoveTowards(pos.anchoredPosition, btnDestination, Time.deltaTime * speed);

📖 참고

참고할 코드 내용




⛔️ 에러


  1. 문제: UI상의 위치를 변경하려 할때 위치 변경이 잘 되지 않았다.
  • 시도: Vector2.Lerp의 스피드 값을 올려보았다 - 스피드 문제가 아니였다
  • 시도: RectTransform를 불러와 값의 고정위치를 변경시켜 주었다
  • 해결: UI상의 좌표를 변경시켜주게 되었다
  • 알게된것: UI상의 좌표를 변경하려면 RectTransform을 불러와 해당값의 anchoredPosition를 변경해주자
  1. 문제: 버튼이 한번만 움직이고 끝났다
  • 시도: 코루틴을 통해 도착할때까지 움직임 코드를 반복해주었다
  • 해결: 도착할때까지 잘움직였다
  • 알게된것: Lerp는 도착점까지 움직여주지 않는다. 마지막 입력 거리만큼만 움직여준다

💾 코드

  public void ButtonEffect(RectTransform curBtnPos)
    {
        OnBtn = true;
        SetBtns();
        
        usingBtn = curBtnPos.gameObject;
        usingBtn.GetComponent<Image>().color = Color.red;
        
        StartCoroutine(moveBtn(backBtnPos, backBtnDestination));
        
        foreach (var pos in btnsPos)
        {
            if (usingBtn != pos.gameObject)
            {
                Vector2 btnDestination = new Vector2(pos.anchoredPosition.x, pos.anchoredPosition.y - 150);
                StartCoroutine(moveBtn(pos, btnDestination));
            }
        }
    }

    private IEnumerator moveBtn(RectTransform movePos, Vector2 desPos)
    {
        while (Vector2.Distance(movePos.anchoredPosition,desPos) > 20f)
        {
            movePos.anchoredPosition =
                Vector2.Lerp(movePos.anchoredPosition, desPos, speed);

            yield return null;
        }

        if (OnBtn)
        {
            backBtn.interactable = true;
        }
        else
        {
            SetBtns();
        }
    }




💭 느낀점


  1. 오늘 너무 무지성으로 했다
  • 객체지향을 항상 생각해야하는데 ㅠ
profile
안석환!

0개의 댓글