- Home /
Question by
amuro21aya · Jan 26, 2012 at 07:53 AM ·
dragcubepuzzle
how can i drag na cube while gameplay?
I'm creating a game about puzzle . how can i drag the object in different position of the scene.. this is look like my gameplay. http://![alt text][1]
[1]: http://26.media.tumblr.com/tumblr_lyeb4hbexu1qaljf7o1_500.jpg
i hope someone help me. this is the last part of my game. And i don't know how to do. Please.. Thank you
Comment
Answer by robert_mathew · Jan 26, 2012 at 04:18 PM
var mouseOverColor = Color.blue;
private var originalColor : Color;
function Start ()
{
originalColor = renderer.sharedMaterial.color;
}
function OnMouseEnter ()
{
renderer.material.color = mouseOverColor;
}
function OnMouseExit ()
{
renderer.material.color = originalColor;
}
function OnMouseDown ()
{
var screenSpace = Camera.main.WorldToScreenPoint(transform.position);
var offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
while (Input.GetMouseButton(0))
{
var curScreenSpace = Vector3(Input.mousePosition.x,Input.mousePosition.y, screenSpace.z);
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;
transform.position = curPosition;
yield;
//print("curScreenSpace"+curScreenSpace);
//print("curPosition"+curPosition);
}
}
function Update()
{
if(Input.GetMouseButton(0))
{
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit ;
if(Physics.Raycast(ray, hit) )
{
//print(hit.transform.gameObject.name);
Debug.DrawLine(Camera.main.transform.position,hit.transform.position,Color.red);
}
}
}
Put this script into the object you want to drag and the object to be dragged should have a collider and make camera as Main
how can i remove the box. I need only the image. Thanks