Hello,
I have a problem with my script. For some reason i get a Format Exception when i try to parseFloat() a String that i get from an InputField.
**The Exception:**
FormatException: Invalid format.
System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Double.cs:209)
System.Single.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Single.cs:183)
UnityScript.Lang.UnityBuiltins.parseFloat (System.String value)
ButtonScript.Calc () (at Assets/Scripts/ButtonScript.js:61)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:144)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:621)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:756)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()
**The Code:**
"#pragma strict
import UnityEngine.UI;"
//INPUT STRINGS
var input1 : String;
var input2 : String;
var input3 : String;
var input4 : String;
//INPUT FIELDS
var inputF1 : InputField; //input Field 1
var inputF2 : InputField; //__""__ 2
var inputF3 : InputField; //...
var inputF4 : InputField; //...
var result : Text;
private final var R : float = 6371000; //Earth's radius in metre
//INPUT VARIABLES
var d : float; //distance to travel
var a1 : float; //latitude in dezimals
var b1 : float; //longitude in dezimals
var brng : float; //Angle you are going to
function Start () {
}
function Update () {
}
//
//BUTTON FUNCTIONS
//
function ExitButton(){
Application.Quit();
}
function InputF1(){
input1 = inputF1.text;
}
function InputF2(){
input2 = inputF2.text;
}
function InputF3(){
input3 = inputF3.text;
}
function InputF4(){
input4 = inputF4.text;
}
function Calc(){
//aFloat = parseFloat(input1); I TRIED ALL THIS BEVORE WIHT ALL
//bFloat = parseFloat(input2); SIMPLE TEST. IT WORKED BACK THEN.
//flaeche = aFloat * bFloat;
//result.text = ""+surface;
d = parseFloat(input3);
a1 = parseFloat(input1);
b1 = parseFloat(input2);
brng = parseFloat(input4);
var a2 = Mathf.Asin( Mathf.Sin(a1)*Mathf.Cos(d/R) +
Mathf.Cos(a1)*Mathf.Sin(d/R)*Mathf.Cos(brng) );
var b2 = b1 + Mathf.Atan2(Mathf.Sin(brng)*Mathf.Sin(d/R)*Mathf.Cos(a1),
Mathf.Cos(d/R)-Mathf.Sin(a1)*Mathf.Sin(a2));
result.text = a2+"°N "+b2+"°W ";
}
//
//BUTTON FUNCTIONS END
//
I have no idea what this Exception is telling me. I am a more or less beginner programmer so please don´t be to harsh on me if the structure of the code is not that good.
The "result" variable is a Text variable which gets displayed in the UI.
Here a picture of the UI. (sry for it beeing German but i think that does not matter that much anyway.)
![alt text][1]
[1]: /storage/temp/74020-coordinatecalc.png
Thanks in Advance!
Lucas
↧