- Home /
Ray Functions with GUI
Well, I'm using DragRigidbody with some restrictions on distance, though that isn't my problem.
I've been trying to render and delete a texture depending on the mouse state.
I was trying to get it to work with PlayMaker, but I've been getting some loops, and I can't seem to fix it, so I'm asking here.
How would I go about doing something like this?:
MouseState_Over: RenderTexture_Hand
MouseState_Click: RenderTexture_HandGrabbing : DeleteTexture_Hand
MouseState_Unclick: DeleteTexture_Handgrabbing : RenderTexture_Hand
MouseState_UnOver: DeleteTexture_Hand
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.
Thanks.
Answer by xortrox · Apr 27, 2013 at 09:11 PM
I'm assuming you use javascript:
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;
}
}
ref links:
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetMouseButtonDown.html http://docs.unity3d.com/Documentation/ScriptReference/GUI.DrawTexture.html http://docs.unity3d.com/Documentation/ScriptReference/Input.GetMouseButtonDown.html http://docs.unity3d.com/Documentation/ScriptReference/Input.GetMouseButtonUp.html
[1]: http://msdn.microsoft.com/en-us/library/sbbt4032(v=vs.80).aspx
Answer by Kemerd · Apr 28, 2013 at 01:55 PM
Thanks! This is perfect for what I need.
I'm new to scripting, but I'm sure I can figure it out.
Thanks again!
Your answer
Follow this Question
Related Questions
Collider weapon hand model 1 Answer
Aligning Cards in Hand Deck 1 Answer
Placing an object 1 Answer
Parent weapon to hand bone 2 Answers