photonView.isMine
Options
Betazero
✭
For some reason I get a bunch of NullReferenceExceptions when trying to use photonView.isMine. It says Object reference not set to an instance of an object. I have my NetworkCharacter script attached in the PhotonView observed area. What am I doing wrong? the debug sends "mine" but also the NRE.Here is the NetworkCharacter script I am trying to get working:
using UnityEngine;
using System;
using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour {
private Vector2 correctPlayerPos;
private Quaternion correctPlayerRot;
void Start(){
PhotonNetwork.sendRate = 20;
PhotonNetwork.sendRateOnSerialize = 10;
}
void Update(){
if (photonView.isMine == false){
transform.position = Vector2.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
Debug.Log ("notmine");
}
if (photonView.isMine){
Debug.Log ("Mine");
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if (stream.isWriting){
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else{
// Network player, receive data
this.correctPlayerPos = (Vector2)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
}
using UnityEngine;
using System;
using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour {
private Vector2 correctPlayerPos;
private Quaternion correctPlayerRot;
void Start(){
PhotonNetwork.sendRate = 20;
PhotonNetwork.sendRateOnSerialize = 10;
}
void Update(){
if (photonView.isMine == false){
transform.position = Vector2.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
Debug.Log ("notmine");
}
if (photonView.isMine){
Debug.Log ("Mine");
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if (stream.isWriting){
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else{
// Network player, receive data
this.correctPlayerPos = (Vector2)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
}
0
Comments
-
Try just using !photonView.isMine
Example:
if (!photonView.isMine){0 -
does the same thing. Thats what I started with.0
-
I get a bunch of NullReferenceExceptions when trying to use photonView.isMine0
-
I went to a pre-adding multiplayer backup and started over. I must have messed something up before because now its working good.
Thanks,
Russell0