- Home /
Can't get max value to be displayed!
This is driving me crazy! I'm designing a UI to track the user's hand speed. I need to get the maximum speed to be displayed on my interface. I've tried many methods but the script below is the closest I can get. This reading I've got is constantly changing and I just can't get the max value to stay there. Any help?!
void Update ()
{
//left hand
initialL = LHand.transform.position;
LHspeed = (initialL - currentL).magnitude / Time.deltaTime;
currentL = initialL;
MaxSpdL = 0;
if(LHspeed>MaxSpdL)
{
MaxSpdL = LHspeed;
}
}
Answer by badProphet · Apr 03, 2012 at 11:12 PM
Where do you declare the variable? Make sure that the declaration of your max value is a public int when and where you declare it!
This is my entire source code. I can't declare $$anonymous$$axSpdL as int because is need to be in float to take on the value of LHSpeed. I'm a beginner. Correct me if im wrong!
using UnityEngine; using System.Collections;
public class LHSpd : $$anonymous$$onoBehaviour
{
public GameObject LHand;
public GameObject Head;
public GameObject Feet;
private Vector3 currentL;
private Vector3 initialL;
private float factor;
private float X;
private float Y;
private float Z;
public static float LHspeed;
public static float $$anonymous$$axSpdL;
public GUISkin s3;
void Update ()
{
//left hand
initialL = LHand.transform.position;
Z = (initialL - currentL).magnitude;
Y = (Head.transform.position - Feet.transform.position ).magnitude;
X = 1.706f;
factor = X / Y;
LHspeed = (Z / Time.deltaTime)*factor;
currentL = initialL;
}
void OnGUI ()
{
$$anonymous$$axSpdL = 0;
if(LHspeed>$$anonymous$$axSpdL)
{
$$anonymous$$axSpdL = LHspeed;
}
GUI.skin = s3;
GUI.Button (new Rect (0,120,150,40),"LH Speed "); GUI.Box (new Rect (151,120,80,40),""+ LHspeed);
}
}