using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DigitalRubyShared
{
public class DemoScriptLagTest : MonoBehaviour
{
private Vector2 offset;
public GameObject _picture;
private void CheckOffset(Vector2 pos)
{
_picture.SetActive(true);
offset = pos - (Vector2)_picture.transform.position;
}
private void Update()
{
if (Input.mousePresent)
{
if (Input.GetMouseButtonDown(0))
{
CheckOffset(Input.mousePosition);
}
else if (Input.GetMouseButton(0))
{
_picture.transform.position = (Vector2)Input.mousePosition - offset;
}
else
{
offset = Vector2.zero;
_picture.SetActive(false);
}
}
else if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == UnityEngine.TouchPhase.Began)
{
CheckOffset(touch.position);
}
transform.position = touch.position - offset;
}
else
{
offset = Vector2.zero;
}
}
}
}
非常简单的脚本,但很有用