Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

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

$
0
0
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);
}






}

}


Viewing all articles
Browse latest Browse all 15755

Trending Articles