.Ismasterclient not working? (AI fighter target not being assigned)

Hi guys, I started up a connection and created a room howeverver I am getting:
UnassignedReferenceException: The variable Target of FighterAI has not been assigned.

this code works fine on single player, trying to implement photon for network play.



using UnityEngine;
using System.Collections;

public class FighterAI : Photon.MonoBehaviour {

// GameObjects-----------------------------
public GameObject[] Targets;
public GameObject Target;
public Quaternion TrueRotation;
public Vector3 TruePosition;
// Float / Int-----------------------------
private int index;
private float turnspeed = 0.2f;
public int AIMode = 1;
public bool BlueTeam;
public float dist;


void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting && PhotonNetwork.isMasterClient)
{
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
// Network player, receive data
this.TruePosition = (Vector3)stream.ReceiveNext();
this.TrueRotation = (Quaternion)stream.ReceiveNext();
}
}





void LateUpdate ()
{


if (Target != null && PhotonNetwork.isMasterClient) {
this.transform.rotation = Quaternion.Slerp (this.transform.rotation, Quaternion.LookRotation (Target.transform.position - transform.position), Time.deltaTime * turnspeed);
dist = Vector3.Distance (Target.transform.position, transform.position);
}





// IF RED TEAM:
if (AIMode == 1 && BlueTeam == false && PhotonNetwork.isMasterClient) {
if (Target == null) {
Targets = GameObject.FindGameObjectsWithTag ("Battle_Points");
index = Random.Range (0, Targets.Length);

}


}

if (AIMode == 1 && BlueTeam == true && PhotonNetwork.isMasterClient) {
if (Target == null) {
Targets = GameObject.FindGameObjectsWithTag ("Battle_Points");
index = Random.Range (0, Targets.Length);
}

}

if (dist < 30 && Target.tag == "Battle_Points" && Target != null && PhotonNetwork.isMasterClient ) {
Targets = GameObject.FindGameObjectsWithTag ("Battle_Points");
index = Random.Range (0, Targets.Length);
}






}

}

Comments

  • Hi theZakMan,

    I saw your question on Unity answers platform as well and I guess, that the 'not assigned' error is thrown here
    if (dist < 30 && Target.tag == "Battle_Points" && Target != null && PhotonNetwork.isMasterClient ) {
    Targets = GameObject.FindGameObjectsWithTag ("Battle_Points");
    index = Random.Range (0, Targets.Length);
    }
    since this is the only location, where you don't check if the game object 'Target' is null.

    To answer your question, if PhotonNetwork.isMasterClient is working: yes, it is. However in the quoted code block above it is the last condition which is checked and it is only checked, if all previous conditions are true. Since you get an exception in the second condition, PhotonNetwork.isMasterClient will never be executed.
Sign In or Register to comment.