Hi i am trying to get distance Code (CSharp): publicfloatGetTotalLength(){ if(vectorPath==null)returnfloat.PositiveInfinity; floattot=0; for(inti=0;i<vectorPath.Count-1;i++)tot+=Vector3.Distance(vectorPath,vectorPath[i+1]); returntot; } i am trying to get value from the above function how to get the return value to the another script.
please...use code tags http://forum-old.unity3d.com/threads/using-code-tags-properly.143875/ and also...proper spacing. everything runs together. otherwise, to get the return value, you just assign the method call to a variable, or you use the method directly. float returnValue = GetTotalLength(); or float addValue = 1.5f + GetTotalLength();
You have to have a reference to that script and call that method from one script to the other. so float returnValue = myScriptWIthMethod.GetTotalLength(); Depending on how your scripts are setup depends on how you'd create that reference.
i am using remainingdistance as the float variable. // path was class Path currentlength; remainingdistance = currentlength.GetTotalLength(); when i use like this i am getting error
List errors. But chances are you are getting a null error there. Also doesn't hurt to show your code for the part that is getting the value.
Original code Code (CSharp): public float GetTotalLength() { if (vectorPath == null) return float.PositiveInfinity; float tot = 0; for (int i = 0; i < vectorPath.Count - 1; i++) tot += Vector3.Distance(vectorPath, vectorPath[i + 1]); return tot; }