- Home /
GUI calling function with return value. I dont know why this doesnt work.
Hey everyone i am trying to call a function within my OnGUI() that does some calculations and then returns a Rect witch i use to draw a box. but for some reason part of my calculation is not being returned. Everything works except when i call the CalculateSpeed function it doesn't return. not even a null. When i just do Debug.Log(CalculateSpeed().toString()) it works fine. Any ideas?
Vector3 CalculateSpeed()
{
Vector3 s = (transform.position - prevPos)/Time.deltaTime;
prevPos = transform.position;
return s;
}
Rect CalculateTargetLead()
{
//Draw Target Lead
float dist = Vector3.Distance(transform.position, cam.transform.position);
float TTT = dist/100; //Time to Target: dist/projectile speed
Vector3 targetSpeed = CalculateSpeed() * TTT;
Vector3 t = cam.WorldToScreenPoint(transform.position + targetSpeed);
Rect tr = new Rect(t.x-10,Screen.height-t.y-10,10,10);
return tr;
}
void OnGUI()
{
GUI.Box(CalculateTargetLead(),"");
}
Comment