This is a bit of an obscure question so I hope it makes sense.
Basically, I have these objects in my scene that add a DragRigidbody component when you click the mouse down and Destroys it when you release with this simple code.
function OnMouseDown(){
gameObject.Find("Plank(Clone)").AddComponent(DragRigidbody);
}
function OnMouseUp(){
Destroy(gameObject.Find("Plank(Clone)").GetComponent(DragRigidbody));
}
Now I want somthing to happen when you only click and release (NO DRAGGING INVOLVED). Does anyone know how I might achieve this without the GUITextures appearing on the first click (I.e when you drag the item)
the easiest would be to simply start a timer and only add the drag aspect after so many seconds alternatly if you attempt to move the cursor
for example
old_cursor_position
if(input.getaxis('mouse X') != 0 && input.getaxis('mouse Y') != 0) // mouse moving
{
add drag component
}
alternatly
onmousedown set timer
onmouseup stop timing, reset to zero
if(timer == its been too long, you've held down for 1 full second)
{
add drag component
}
I’m not sure what you mean about GUITextures. But the following code should prevent you from taking action if the mouse is dragged during the click:
var dragged : boolean = false;
function OnMouseDown(){
dragged = false;
gameObject.Find("Plank(Clone)").AddComponent(DragRigidbody);
}
function OnMouseDrag(){
dragged = true;
}
function OnMouseUp(){
Destroy(gameObject.Find("Plank(Clone)").GetComponent(DragRigidbody));
if (!dragged)
{
// Extra functionality -- only if not dragged.
}
}