Something sort of like in the HPL Engine (Amnesia), where when it’s mouseover, and it shows a hand. You click, it picks up the object (DragRigidBody with Range Addon), and shows a hand grabbing.
I’m looking for the hand rendering script, since DragRigidBody is sufficient enough for me.
var mpos = Vector2.zero; //assign mouse position to this
var mstate = 0; //could use an [**enum**][1] for this
var mdown = false;
var texture_HandOver : Texture2D;//Assign your normal "hover/over" cursor texture to this
var texture_HandGrab : Texture2D;//Assign your grab cursor texture to this
var hoveringObject = false;//It's up to you to make the logic that triggers this.
function Update()
{
if(Input.GetMouseButtonDown(0))//check if right mbtn was clicked this frame
{
mstate = 1;//1 = handgrabbing
mdown = true;
}
if(Input.GetMouseButtonUp(0))//check if right mbtn was clicked this frame
{
if(mdown)
{
/*
Triggers if the mouse was held down in a previous frame then released in this
frame.
*/
mstate = 0;//back to default
mdown = false;
}
}
}
function OnGUI()
{
switch(mstate)
{
case 0:
if(hoveringObject)
{
GUI.DrawTexture(
new Rect(mpos.x, mpos.y, texture_HandOver.width, texture_HandOver.height),
texture_HandOver
);
}
//if no object is hovered then the hand simply wont be drawn.
break;
case 1:
GUI.DrawTexture(
new Rect(mpos.x, mpos.y, texture_HandGrab.width, texture_HandGrab.height),
texture_HandGrab
);
break;
}
}
Glad I could help.
– xortrox