I would like to drage gameObject with the mouse, i have tried the following code, which gets the object to “disappeear”, then realised it may be an issue with having the screen split with both views an only on mouse, ^^
what is the best way to get around the problem?
#pragma strict
private var screenPoint:Vector3;
private var offset:Vector3;
//Drop this onto a gameobject, use the collider that matches your type of gameobject
// using UnityEngine;
// using System.Collections;
// [RequireComponent(typeof(MeshCollider))]
function Start () {
}
function Update () {
// this.transform.position.x ++;
}
function OnMouseDown()
{
Debug.Log(this.name );
print(this.transform.position.x);
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
function OnMouseDrag()
{
this.transform.position.x = Input.mousePosition.x;
var curScreenPoint:Vector3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
//var curScreenPoint:Vector3 = new Vector3( Input.mousePosition.x, this.transform.position.y, this.transform.position.z);
var curPosition:Vector3 = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}