- Home /
Photon Bike Racing Game Position Problem
I am getting waypoints of all Players with Tag = Player and check that which player has greater waypoint. But when i get the waypoints of other player the null is passing. Here is my both scripts
public class CountDownTF : Photon.MonoBehaviour {
public Texture[] allGUI = new Texture[3];
public GameObject GuiT ;
bool SpawnAIStat;
GameObject Lobby;
GameObject spawn;
public GameObject GUIControlButtons;
public GameObject LapManager;
/*------------------------------*/
public GameObject[] Bikes;
public MotoBike002[] bike_aiscripts;
int count = 0;
/*------------------------------*/
void Start () {
bike_aiscripts = new MotoBike002[PhotonNetwork.room.playerCount];
Lobby = GameObject.Find ("Lobby");
SpawnAIStat = Lobby.GetComponent<GUILobby>().SpawnAIStat;
StartCoroutine (Show());
}
IEnumerator Show(){
for(int i = 3 ; i >= 0 ; i--){
yield return new WaitForSeconds(2.0f);
photonView.RPC ("CountDownRPC", PhotonTargets.All , i);
}
if (PhotonNetwork.isMasterClient && SpawnAIStat) {
SpawnAI();
}
}
void SetCarMaster(){
GameObject[] allPl = GameObject.FindGameObjectsWithTag ("Player");
foreach (GameObject pl in allPl)
{
pl.GetComponent<CarMasterNetworkTF>().SetWheelRpc();
}
}
void SpawnAI(){
int j = 0;
float speed = 150.0f;
GameObject AI;
for (int i = 4; i<8; i++) {
spawn = GameObject.Find ("Spawn" + i.ToString ());
speed += (25* j);
AI = (GameObject)PhotonNetwork.Instantiate ("AICar2", spawn.transform.position, spawn.transform.rotation, 0);
AI.SendMessage("SetTopSpeed",speed);
j++;
}
}
[RPC]
void CountDownRPC(int Count)
{
if (Count != 0)
{
GuiT.guiTexture.texture = allGUI [Count - 1];
}
else
{
GuiT.SetActive (false);
GameObject[] alPl = GameObject.FindGameObjectsWithTag ("Player");
foreach (GameObject p in alPl)
{
p.rigidbody.constraints = RigidbodyConstraints.None;
}
GameObject.FindGameObjectWithTag("Player").SendMessage("GettingTotalPlayers", PhotonNetwork.room.playerCount);
Bikes = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject Objs in Bikes){
Debug.Log("COUNT = " + count);
if (count < Bikes.Length)
{
bike_aiscripts[count] = Objs.GetComponent<MotoBike002>();
Debug.Log("BIKE AI SCRIPT = " + bike_aiscripts.Length + " Biker Name = " + Bikes[count].name);
count++;
}
}
GUIControlButtons.SetActive(true);
LapManager.SetActive(true);
SetCarMaster ();
}
}
}
here is the script which calculate the position
public class asd : Photon.MonoBehaviour {
static public int ads_looper = 0;
public int Position = 0;
public int myLap = 0;
public int myCheckpoints = 0;
private int total_players;
private int pos_sys; //+1 of total_players
private int myBikeDist;
private int[] bike_distance; //array that contains distances of all other bikes
public GameObject[] Bikes;
public MotoBike002[] bike_aiscripts;
public GameObject anim;
private int counter;
private int last_pos;
private bool flag_anim;
private string[] selected_names;
private bool flag_finished;
public CountDownTF cdt;
void GettingTotalPlayers(int p)
{
total_players = p;
pos_sys = p + 1;
last_pos = pos_sys;
}
void Start(){ cdt = GameObject.Find("Script").GetComponent<CountDownTF>();}
void Update(){calculate_position();}
void calculate_position()
{
if(flag_finished)
return;
takeoff_checker=1000;
myBikeDist = gameObject.GetComponent<MotoBike002>().myWayPoint;
Position=pos_sys;
for(int i =0; i<PhotonNetwork.room.playerCount; i++)
{
if(gameObject.name != cdt.bike_aiscripts[i].name)
{
Debug.Log("jjjjjjjj = " + cdt.bike_aiscripts[i].myWayPoint + " " + cdt.bike_aiscripts[i].name + " " + i);
bike_distance[i] = cdt.bike_aiscripts[i].myWayPoint;
}
if(bike_distance[i]<myBikeDist)
{
Position--;
int temp = myBikeDist-bike_distance[i];
if(takeoff_checker>temp)
{
takeoff_checker=temp;
}
}
}
if(takeoff_checker==1000)
{
takeoff_checker=0;
}
if(Position<last_pos && !flag_anim && takeoff_checker>=2)
{
if(flag_anim_counter%2==1)
{
print("here");
anim.animation.CrossFade("act_take");//,0.01);act_take
flag_anim=true;
}
flag_anim_counter++;
// print("pos is ="+Position+" last pos is="+last_pos);
last_pos = Position;
}else if(flag_anim){
if(!anim.animation.IsPlaying("DriveLoop") && !anim.animation.IsPlaying("act_take") )
{
anim.animation.CrossFade("DriveLoop",0.01f);
flag_anim=false;
}
}
if(Position>last_pos && !flag_anim && takeoff_checker>=2)
{
last_pos = Position;
}
}
}
sorry for so lengthy scripts but what can i have to do my 2 question already had been de-moderate by moderator for the lack of code. any assistance may very appreciated.
Comment
line 124 passess null when getting waypoint of other players. who can i do this any suggestion.??