Problem with the stream

Options
I have a simple playerHealth script and It was working fine, but when I made a second map it started giving me this error:
InvalidCastException: Cannot cast from source type to destination type.
multiplayer.PlayerHealth.OnPhotonSerializeView (.PhotonStream stream, .PhotonMessageInfo info) (at Assets/Scripts/multiplayer/PlayerHealth.cs:56)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
PlayerHealthScript:

void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(health);
}

if (stream.isReading)
{
health = (int)stream.ReceiveNext();
}
}

The error shows up when player gets hit (using RPC call)

Can't manage to fix this, anyone had the same problem?

Comments

  • Dev
    Options
    If the variable health is a float then there's your answer