Notice
Recent Posts
Recent Comments
Link
스토리지
[4.30] LobbyScene R&D 본문
1. 버튼을 클릭하면 UI 상의 캐릭터가 일정한 각도로 방향에 맞게 회전
using UnityEngine;
using UnityEngine.UI;
public class LobbyScene : MonoBehaviour
{
public GameObject obj;
public Button btnL;
public Button btnR;
// Start is called before the first frame update
void Start()
{
this.btnL.onClick.AddListener(() =>
{
Debug.Log("L Button pressed");
this.obj.transform.Rotate(0, 30, 0);
});
this.btnR.onClick.AddListener(() =>
{
Debug.Log("R Button pressed");
this.obj.transform.Rotate(0, -30, 0);
});
}
}
2. 드래그 하는 방향으로 캐릭터를 회전
IDragHandler Interface를 이용했다.
LobbyScene.cs
using UnityEngine;
using UnityEngine.UI;
public class LobbyScene : MonoBehaviour
{
public GameObject obj;
public Button btnL;
public Button btnR;
public UIDragTest test;
// Start is called before the first frame update
void Start()
{
this.btnL.onClick.AddListener(() =>
{
Debug.Log("L Button pressed");
this.obj.transform.Rotate(0, 30, 0);
});
this.btnR.onClick.AddListener(() =>
{
Debug.Log("R Button pressed");
this.obj.transform.Rotate(0, -30, 0);
});
this.test.onDragX = (delta) =>
{
this.obj.transform.Rotate(0, delta * -1, 0);
};
}
}
UIDragTest.cs
using UnityEngine;
using UnityEngine.EventSystems;
public class UIDragTest : MonoBehaviour, IDragHandler
{
public System.Action<float> onDragX;
public void OnDrag(PointerEventData eventData)
{
this.onDragX(eventData.delta.x);
}
}
'Unity > 유니티 기본' 카테고리의 다른 글
[06.17] SNS 로그인 - GPGS Unity 세팅 (0) | 2021.06.17 |
---|---|
유니티는 Visual Studio Code를 사용하자 (0) | 2021.05.04 |
[4.30] 데미지가 지정된 위치에 출력되지 않는 문제 (0) | 2021.04.30 |
[4.29] - 세미 프로젝트 1 (0) | 2021.04.29 |
[4.29] 미니프로젝트 1 - 조이스틱으로 플레이어 움직이기 및 공격모션 (0) | 2021.04.29 |
Comments