Unity New UI : How To Build Draggable UI

Unity New UI : How To Build Draggable UI

A way to implement  Draggable UI :

using UnityEngine;
using System.Collections;

public class vUIDrag : MonoBehaviour {

	float OffsetX;
	float OffsetY;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public void BeginDrag(){
		OffsetX=transform.position.x-Input.mousePosition.x;;
		OffsetY=transform.position.y-Input.mousePosition.y;;
	}
	                 
	public void OnDrag(){


		transform.position= new Vector3( Input.mousePosition.x +OffsetX, Input.mousePosition.y +OffsetY);
	}
}

 
 

  按個讚!~支持本站!~

FB推薦載入中