- Home /
Question by
rd42 · May 01, 2010 at 05:05 PM ·
iphonerepeatbutton
RepeatButton action upon release
I want to collect accelerometer force while a button is held down and when it is released a apply that to a rigid body. How do I make it so it does that?
function OnGUI () {
if (GUI.RepeatButton (Rect (10,10,150,50), "Apply Upward Force")) {
time += Time.deltaTime;
total += iPhoneInput.acceleration.y;
}
then i want to do something like myRigidBody.AddForce (Vector3.up * total);
I don't want the myRigidBody.AddForce to execute until after the data ids collected though.
Comment
Answer by AngryAnt · May 30, 2010 at 04:53 PM
You could do something like this:
function OnGUI ()
{
if (GUI.RepeatButton (Rect (10,10,150,50), "Apply Upward Force"))
{
time += Time.deltaTime;
total += iPhoneInput.acceleration.y;
}
else if (Event.current.type == EventType.MouseUp && total != 0)
{
ApplyTheForce ();
time = total = 0;
}
}
Answer by Narven · May 01, 2010 at 08:22 PM
Probably o need a variable to hold the max acceleration force and then when do something like
var maxAcc = 80;
if(iPhoneInput.acceleration.y => maxAcc) { // apply to rigidbody }
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to Use Activity Indicator in Unity3d 1 Answer
Unity iPhone Tutorial? 1 Answer