- Home /
Question by
ramjigeddam · Dec 03, 2013 at 08:05 AM ·
javascript
How can i drag my cubes at a time with mouse....?
hi every one i am new to unity scripting :(
i have 3 cube with different position, i have to drag these three cubes at a time with mouse. but these this is not working, i giving my code i tried a lot but its is not working. please help any one
#pragma strict
private var screenPoint: Vector3;
private var offset: Vector3;
private var curScreenPoint : Vector3;
private var curPosition : Vector3;
public var peel1:GameObject[];
peel1=GameObject.FindGameObjectsWithTag("Player");
function Start () {
}
function Update () {
}
function OnMouseDown ()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
Screen.showCursor = false;
}
function OnMouseDrag()
{
curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
for(var i=0;i<peel1.Length;i++)
{
peel1.transform.position = curPosition;
}
}
function OnMouseUp()
{
Screen.showCursor = true;
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Walking animation problem. 0 Answers
JS Unity Boolean 'not possible to evoke an expression of type 'boolean'' 1 Answer
Multitouch iPhone error! Help 1 Answer
Problems with java script. 1 Answer