Welcome,
Guest
. Please
login
or
register
.
December 03, 2024, 12:03:00 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Repeat Buttons NGUI
« previous
next »
Print
Pages: [
1
]
Author
Topic: Repeat Buttons NGUI (Read 7173 times)
stety2
Guest
Repeat Buttons NGUI
«
on:
August 18, 2012, 03:04:03 AM »
How can I do Repeat Buttons in NGUI?
Thank you for your answer.
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Repeat Buttons NGUI
«
Reply #1 on:
August 18, 2012, 03:28:37 AM »
Add a script to it that does something in Update() once it has been pressed?
Logged
stety2
Guest
Re: Repeat Buttons NGUI
«
Reply #2 on:
August 18, 2012, 03:39:21 AM »
Can you please show me an example or explain this in more detail?
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Repeat Buttons NGUI
«
Reply #3 on:
August 18, 2012, 03:43:23 AM »
using
UnityEngine
;
public
class
RepeatButton
:
MonoBehaviour
{
public
float
interval
=
0
.
25f
;
bool
mIsPressed
=
false
;
float
mNextClick
=
0f
;
void
OnPress
(
bool
isPressed
)
{
mIsPressed
=
isPressed
;
mNextClick
=
Time
.
realtimeSinceStartup
+
interval
;
}
void
Update
(
)
{
if
(
mIsPressed
&&
Time
.
realtimeSinceStartup
<
mNextClick
)
{
mNextClick
=
Time
.
realtimeSinceStartup
+
interval
;
// Do what you need to do, or simply:
//SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
}
}
}
Logged
stety2
Guest
Re: Repeat Buttons NGUI
«
Reply #4 on:
August 18, 2012, 04:07:18 AM »
This is not working.
Console prints only once: Touch on button
using
UnityEngine
;
public
class
RepeatButtons
:
MonoBehaviour
{
public
float
interval
=
0
.
25f
;
bool
mIsPressed
=
false
;
float
mNextClick
=
0f
;
void
OnPress
(
bool
isPressed
)
{
mIsPressed
=
isPressed
;
mNextClick
=
Time
.
realtimeSinceStartup
+
interval
;
}
void
Update
(
)
{
if
(
mIsPressed
&&
Time
.
realtimeSinceStartup
<
mNextClick
)
{
mNextClick
=
Time
.
realtimeSinceStartup
+
interval
;
print
(
"touch on button"
)
;
}
}
}
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Repeat Buttons NGUI
«
Reply #5 on:
August 18, 2012, 04:08:32 AM »
That's probably because you have "Collapse" turned on in the console log.
Logged
stety2
Guest
Re: Repeat Buttons NGUI
«
Reply #6 on:
August 18, 2012, 04:10:19 AM »
Thank you and I'm sorry.
Logged
kruncher
Jr. Member
Thank You
-Given: 0
-Receive: 0
Posts: 78
Re: Repeat Buttons NGUI
«
Reply #7 on:
October 17, 2013, 06:05:00 AM »
Here is a variation which has an initial delay. Thought I would post this should it be of use to anybody
using
UnityEngine
;
public
class
RepeatButtons
:
MonoBehaviour
{
public
float
delay
=
1
.
00f
;
public
float
interval
=
0
.
25f
;
bool
mIsPressed
=
false
;
float
mNextClick
=
0f
;
void
OnPress
(
bool
isPressed
)
{
mIsPressed
=
isPressed
;
mNextClick
=
Time
.
realtimeSinceStartup
+
delay
;
// Perform action as soon as button is pressed.
if
(
isPressed
)
PerformAction
(
)
;
}
void
Update
(
)
{
// Adjusted condition slightly...
if
(
mIsPressed
&&
Time
.
realtimeSinceStartup
>=
mNextClick
)
{
mNextClick
=
Time
.
realtimeSinceStartup
+
interval
;
PerformAction
(
)
;
}
}
void
PerformAction
(
)
{
print
(
"touch on button"
)
;
}
}
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Repeat Buttons NGUI