Welcome,
Guest
. Please
login
or
register
.
February 11, 2025, 07:15:36 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Make an object always follow your mouse
« previous
next »
Print
Pages: [
1
]
Author
Topic: Make an object always follow your mouse (Read 2036 times)
matt1
Newbie
Thank You
-Given: 2
-Receive: 0
Posts: 28
Make an object always follow your mouse
«
on:
November 29, 2014, 09:50:44 AM »
Hi,
I am trying to make a GUI object always follow my mouse, I've tried to alter the DraggableObject script to always be true but so far havn't prevailed, is there an easier way to do it?
Many thanks
Matt
Logged
matt1
Newbie
Thank You
-Given: 2
-Receive: 0
Posts: 28
Re: Make an object always follow your mouse
«
Reply #1 on:
November 29, 2014, 10:41:31 AM »
I managed to achieve this by doing:
public
class
DragGUI
:
MonoBehaviour
{
public
GameObject DraggableSprite
;
public
Camera NGUICam
;
public
Vector3 MoveUI
(
Vector3 Pos, Transform localSpace, Camera cameraNGUI
)
{
Pos
.
x
=
Mathf
.
Clamp01
(
Pos
.
x
/
Screen
.
width
)
;
Pos
.
y
=
Mathf
.
Clamp01
(
Pos
.
y
/
Screen
.
height
)
;
Vector3 WorldPos
=
cameraNGUI
.
ViewportToWorldPoint
(
Pos
)
;
return
localSpace
.
InverseTransformPoint
(
WorldPos
)
;
}
void
Update
(
)
{
DraggableSprite
.
transform
.
localPosition
=
MoveUI
(
Input
.
mousePosition
, DraggableSprite
.
transform
.
parent
, NGUICam
)
;
}
}
Logged
matt1
Newbie
Thank You
-Given: 2
-Receive: 0
Posts: 28
Re: Make an object always follow your mouse
«
Reply #2 on:
November 29, 2014, 12:26:29 PM »
A problem i've ran into, that I can't figure a way around is:
If I have MouseButton(0) or (1) held down then void OnHover(bool IsOver) will not work, how can I work around this?
Thanks
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Make an object always follow your mouse
«
Reply #3 on:
November 30, 2014, 05:50:04 AM »
When the mouse button is held down, you get OnDragOver/OnDragOut instead of OnHover.
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Make an object always follow your mouse