When I try to do something like this:
gCon.ReturnFinalPos (gCon.freeLetters.IndexOf (this as Object), Vector2.Lerp (remotePos, targetPos2, 0.5));
or
if (gCon.displacedLetters.ContainsKey (gCon.freeLetters.IndexOf (this as Object)))
I get
BCW0028: WARNING: Implicit downcast from 'Object' to 'LoneLetter'.
I know what the warning means, I added the “as Object” because IndexOf in a generic list or dictionary won’t take the the variable type of whatever it’s a List.< T > of, which seems stupid to me but that’s how it works, it threw an error if I gave it anything other than an Object.
The closest I could find to a solution was a for … in statement where the type is left to the compiler’s imagination, but I don’t think that applies to what I’m trying to do.
The reason I’m getting array indexes in the first place is so I can keep local and remote copies of an object in sync over a network with RPC calls ( for 2 players, each has an ‘allMyUnits’ list and an ‘allYourUnits’ list, whose indices and contents are mirrored crosswise in a consistent way. ) The script on the individual unit figures out its place on the game controller’s local unit list, then sends that as a byte to the other player with the move order, the other player’s game controller script receives the RPC and then passes the order on to the script of the matching index on the remote unit list.
Am I doing it wrong?