using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class vitualJoystick : MonoBehaviour, IDragHandler,IPointerDownHandler,IPointerUpHandler
{
private Image bgImg;
private Image joystckImg;
private Vector3 inputVector;
private void Start()
{
bgImg = GetComponent<Image> ();
joystckImg = transform.GetChild (0).GetComponent<Image> ();
}
public virtual void OnDrag(PointerEventData ped)
{
Vector2 pos;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle (bgImg.rectTransform, ped.position, ped.pressEventCamera, out pos)) {
Debug.Log ("sdf");
}
}
public virtual void OnPointerDown(PointerEventData ped)
{
OnDrag (ped);
}
public virtual void OnPointerUP(PointerEventData ped)
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class vitualJoystick : MonoBehaviour, IDragHandler,IPointerDownHandler
{
private Image bgImg;
private Image joystckImg;
private Vector3 inputVector;
private void Start()
{
bgImg = GetComponent<Image> ();
joystckImg = transform.GetChild (0).GetComponent<Image> ();
}
public virtual void OnDrag(PointerEventData ped)
{
Vector2 pos;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle (bgImg.rectTransform, ped.position, ped.pressEventCamera, out pos)) {
pos.x = (pos.x / bgImg.rectTransform.sizeDelta.x);
pos.y = (pos.y / bgImg.rectTransform.sizeDelta.y);
inputVector = new Vector3(pos.x * 2 + 1, 0, pos.y * 2 - 1);
Debug.Log(inputVector);
}
}
public virtual void OnPointerDown(PointerEventData ped)
{
OnDrag (ped);
}
public virtual void OnPointerUP(PointerEventData ped)
{
}
}
'DEV > Unity' 카테고리의 다른 글
유니티 이동 (0) | 2017.05.18 |
---|---|
저장시스템 구현중 (0) | 2017.05.16 |
[Unity] 한번만 재생 PlayClipAtPoint( audioclip, position) (1) | 2017.04.20 |
Unity 3D: 레이케스팅 Raycasting (0) | 2017.04.20 |
3D Unity 과제 (0) | 2017.04.20 |