This might seem a noob question to ask but I am using gamespark with unity. I am sending vector2 in the pack like this:
data.SetVector2(1, new Vector2(1.0f, 1.0f, 1.0f));
and I get it from the packet like:
Vector2 a = _packet.Data.GetVector2 (1);
But I am getting the following error: Cannot implicitly convert type UnityEngine.Vector2? to UnityEngine.Vector2.
The '?' means it is a "nullable" type. To convert to a Vector2, do
Vector2 a = _packet.Data.GetVector2(1).Value;
Here is a link on nullable types from MS: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/
Nullable types also have the option to check if the value is null or not with the HasValue property. If you aren't certain that GetVector2 actually returns a valid value, you should check HasValue and respond appropriately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With