csharp unity / 2d draggable gameobject

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp unity / 2d draggable gameobject相关的知识,希望对你有一定的参考价值。

public class Plane : MonoBehaviour
{

	private bool isMouseDown = false;
	private Vector3 lastMousePosition = Vector3.zero;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetMouseButtonDown(0))
		{
			isMouseDown = true;
		}

		if (Input.GetMouseButtonUp(0))
		{
			isMouseDown = false;
			lastMousePosition = Vector3.zero;
		}

		if (isMouseDown)
		{
			if (lastMousePosition != Vector3.zero)
			{
				Vector3 offset = Camera.main.ScreenToWorldPoint(Input.mousePosition) - lastMousePosition;
				this.transform.position += offset;
			}

			lastMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		}
	}
}

以上是关于csharp unity / 2d draggable gameobject的主要内容,如果未能解决你的问题,请参考以下文章

unity无法创建2d项目

unity2d如何判断高度

unity2d动画位置不在一起怎么调整

unity2d游戏入门开发【三】各个面板作用

csharp UI效果2D

csharp /团结/ 2D /相机/设置