-
[유니티] 중심 회전하다 클릭하면 직진하기게임 개발 2020. 1. 28. 17:03
상점에서 change한 로켓이 시작 시에 지구를 중심으로 공전하는 것 까지 완성되어 있는 상태이다.
화면을 클릭하면 회전을 멈추고 그 방향으로 직진하는 코드를 짜보려한다.
1. 화면터치
점수가 표시될 부분과 일시정지 버튼을 제외한 화면을 터치하면
이벤트가 실행되도록 만드려 한다.
아래 방법으로 문제를 해결했다.
우선 일시정지 버튼, 점수 표시 부분, 새롭게 만들어준 투명 버튼
모두 한 canvas 안에 넣었다.
새롭게 만든 투명한 버튼을 canvas크기로 해서 깔아준다.
sprite 속성에서 layer를 조정하여 버튼과 점수 부분 모두 투명 버튼
위에 깔아주었다.
또한 pause 부분 창에 해당하는 부분도 투명 버튼 위에 깔아주었다.
2. 회전 멈추기
1번에서 만든 버튼에 이벤트를 추가하였다.
단순히 화면을 터치하면 bool 타입의 touch 변수가 true로 바뀌고 Update함수에서 동작하던 코드가 멈추게 된다.
3. 로켓 오브젝트 방향 구하기
4. 그 방향 그대로 직진하기
처음에는 로컬 방향을 구해서 그 방향으로 이동하도록 하려고 했는데 복잡함을 느껴서
로켓의 로컬 방향 y축에 있는 어떤 target 지점을 설정해서 오브젝트에서 오브젝트로 이동하는 코드를 썼다.
'게임 개발' 카테고리의 다른 글
[유니티] 화면 비율 고정 (0) 2020.11.09 [GitHub] merge시 충돌 코드 처리하기 (0) 2020.09.03 [유니티] 플레이_오브젝트 레이어 설정 (0) 2020.01.16 [유니티] 플레이_조건 맞는 행성 만들기 (0) 2020.01.15 [유니티] 플레이_오브젝트 위치구하기 (0) 2020.01.15