- Home /
Problem Button Click with Cursor, Cursor attach the gameobject
Hi! I have problem with Cursor press button it cursor attach gameobject, Cursor again click detach with gameobject, Click right destroy Gameobject with mouse.
How do you not understand, it example: Here
I needs it, Help me!
Dude , please you have to be more clear with your question! Do you have a problem with your English? As I got you that you want to attach the gameObject to the mouse cursor when clicked for the first time, and detach for the second click? so what's wrong and what's your problem?
Answer by moghes · Jun 03, 2012 at 06:27 PM
Dude this code might help you with the attach and the detach, although I didn't try but I did something similar lately, you have to attach this script to the gameObject that you want to attach/detach.
and concerning the destroy, the guys will help you or if i get smth soon, i'll post here!
private isAttached = false; private var curScreenPoint:Vector3; private var curPosition:Vector3;
function OnMouseDown() {
screenPoint_Globe = GlobeCam.WorldToScreenPoint(gameObject.transform.position);
if(isAttached)
{ isAttached = false; }
if(!isAttached)
{ isAttached = true; }
}
function Update() { if(isAttached) { curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint_Globe.z);
curPosition = GlobeCam.ScreenToWorldPoint(curScreenPoint);
gameObject.transform.position = curPosition;
} }
Answer by Jumper28 · Jun 04, 2012 at 08:01 PM
How do you not understand? similar to http://www.youtube.com/watch?v=mOEUkdob5bQ