So, I am working on an online FPS game (I'followed quill18's youtube tutorials and now i work on my own ideas) and i got a really weird problem.
As you can see in the code bellow i set everything to be sent or received by players. Everything works if I build the project and run it two times. But if I try to test things out with unity and just one build I get the following error:
NullReferenceException
UnityEngine.Animator.SetFloat (System.String name, Single value) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/AnimatorBindings.cs:176)
The method is this one and the problem points at line > anim.SetFloat("Speed", (float)stream.ReceiveNext()); :
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if(stream.isWriting){
//my player
Debug.Log("Writing");
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(anim.GetFloat("Speed"));
stream.SendNext(anim.GetBool("Jumping"));
stream.SendNext(anim.GetFloat("AimAngle"));
stream.SendNext(PhotonNetwork.player.name);
}
else{
//network player
Debug.Log("Receiving");
realPosition = (Vector3) stream.ReceiveNext();
realRotation = (Quaternion) stream.ReceiveNext();
anim.SetFloat("Speed", (float)stream.ReceiveNext());
anim.SetBool("Jumping", (bool)stream.ReceiveNext());
realAimAngle = (float) stream.ReceiveNext();
playerName.GetComponent ().text = (string) stream.ReceiveNext();
if(gotFirstUpdate==false){
transform.position=realPosition;
transform.rotation = realRotation;
anim.SetFloat("AimAngle", realAimAngle);
gotFirstUpdate=true;
}
}
}
Any ideas what is causing this?? (I already updated my photon plugin and reimported it but still nothing).
↧