Get it on Google Play


Wm뮤 :: 유니티 커스텀 인터페이스

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2021. 6. 24. 18:23 Unity/C#

 

 

 

 

드래그 체크

using System.Collections;
using System.Collections.Generic;
using UnityEngine;



using UnityEngine.EventSystems;
using UnityEngine.UI;
public class CustomInteface : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    public GameObject ui;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    public void OnBeginDrag(PointerEventData data)
    {
    }



    public void OnDrag(PointerEventData data)
    {
    }




    public void OnEndDrag(PointerEventData data)
    {
        var zPos = transform.position.z;

        var pos = Camera.main.ScreenToWorldPoint(data.position);
        pos.z = zPos;


        var pressPos = Camera.main.ScreenToWorldPoint(data.pressPosition);
        pressPos.z = zPos;




        ui.transform.position = pos;
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}

 

 

 

 

아이템 드래그

        if (Vector2.Distance(eventData.pressPosition,eventData.position)>300)
        {
            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(GetComponent<RectTransform>(), eventData.position, eventData.pressEventCamera, out var worldPoint))
            {
                transform.position = worldPoint;
            }
        }
        else
        {
            transform.position = eventData.pressPosition;
        }

 

'Unity > C#' 카테고리의 다른 글

유니티 좌표계산 모음  (0) 2021.07.01
유니티 기즈모 (Gizmo) 관련코드  (0) 2021.06.15
유니티 안드로이드 빌드관련 스크립트  (0) 2021.06.10
posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입