I changed .NET version in my project to 4.6, but I still cannot use GeoCoordinate class. Haven't I done something wrong or Unity don't fully support .NET 4.6?
-
1Possible duplicate of [Why can't I see .Net 4.6 option for API Compatibility Level?](https://stackoverflow.com/questions/42513782/why-cant-i-see-net-4-6-option-for-api-compatibility-level) – Serlite Aug 10 '17 at 14:09
2 Answers
Unity supports possibly all the C# 6 features. It does not support all .NET 4.6 API because it uses Mono. Even with .NET 3.5, there are also many other API that Unity did not support because Mono did not support it.
This should not be a problem at-all. You can get the GeoCoordinate API replica from github. All you need are the GeoCoordinate.cs
and the GeoPosition.cs
files.
The function names and everything else is interchangeable with Microsoft's System.Device.Location.GeoCoordinate
.
Sample Usage when imported into Unity and after initializingGPS (if using with Unity's GPS API):
LocationInfo gpsInfo = Input.location.lastData;
LocationInfo gpsInfo2 = Input.location.lastData;
GeoCoordinate pin1 = new GeoCoordinate(gpsInfo.latitude, gpsInfo.longitude);
GeoCoordinate pin2 = new GeoCoordinate(gpsInfo2.latitude, gpsInfo2.longitude);
double distanceBetween = pin1.GetDistanceTo(pin2);

- 121,791
- 22
- 236
- 328
"IL2CPP fully supports the new .NET 4.6 APIs, so you still get the benefits of writing in C# and the performance of native C++. If you find any issues, please jump over to the forum. "
https://blogs.unity3d.com/2017/07/11/introducing-unity-2017/
This is experimental features, I don't think a lot of people are using it yet, so you'll probably have more answers on the dedicated forum :
https://forum.unity3d.com/forums/experimental-scripting-previews.107/

- 2,626
- 4
- 26
- 57