嗨我有一个精灵在鼠标左键单击屏幕上移动,我的问题是精灵可以被拖离场景 . 我相信使用mathf和clamp但是无法想象如何将它插入到这个脚本中 .
尝试在sprite上插入一个基本的mathf.clamp脚本,但结果是精灵会快速地在我的夹子的顶部和底部之间轻弹 .
using System.Collections;
使用System.Collections.Generic;使用UnityEngine;
公共类DragMove:MonoBehaviour {
public GameObject gameObjectToDrag; // refer to Go that being dragged
public Vector3 Gocenter; // gameobject centre
public Vector3 touchPosition; // touch or click position
public Vector3 offSet; // vector between touchpoint/mouse click to the object centre
public Vector3 newGOCenter; // new center of object
RaycastHit hit; // store hit object information
public bool draggingmode = false; //
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
//********************************
// **Click to Drag****************
//********************************
如果UNITY_EDITOR
感谢您的任何帮助
1 回答
我用了这段代码