In my LaunchAnswers [RPC] function I do a check to see if user is the master client.
I want to spawn an array of answers in two different places in my scene depending if they are first player in the experience or second.
This code is also spawning 16 instances of answers instead of 8. Some of the instances don’t contain any text either.
Its like the LaunchAnswers function is being called 4 times instead of once on each of the 2 players.
Is checking for master client the right thing here? I want to know if they were the first in the room.
Can you help straiten me out?
//This part works
public override void OnJoinedRoom()
{
if (PhotonNetwork.CurrentRoom.PlayerCount > 1)
{
this.photonView.RPC("PlayStartGameAudio", RpcTarget.AllBuffered);
}
}
//this part works
[PunRPC]
public IEnumerator PlayStartGameAudio()
{
StartGame.Play();
yield return new WaitForSeconds(2.0f);
this.photonView.RPC("StartTheGame", RpcTarget.AllBuffered);
}
//this works
[PunRPC]
public void StartTheGame()
{
questionNumber = 0;
scoreBoardManagr_player1.ResetScore();
scoreBoardManagr_player2.ResetScore();
theCurrentQuestion = gameObject.GetComponent<GetTheQuestions>().GetTheQuestion(questionNumber);
//SHow the question
int i = 0;
foreach (TextMeshPro questionboard in questionboards)
{
questionboards[i].SetText(theCurrentQuestion.Text);
i++;
}
this.photonView.RPC("LaunchAnswers", RpcTarget.AllBuffered);
}
//Issues with this function
[PunRPC]
public IEnumerator LaunchAnswers()
{
answers.Clear();
CancelInvoke();
int answerCount = 0;
var angle = .01f;
if (PhotonNetwork.IsMasterClient)
{
foreach (GetTheQuestions.Answer answer in theCurrentQuestion.Answers)
{
answerGo = PhotonNetwork.Instantiate(answerfab.name, launcher_Player1[answerCount].transform.position, Quaternion.identity);
answerGo.GetComponent<TextMeshPro>().text = theCurrentQuestion.Answers[answerCount].Text + "_Master";
answers.Add(answerGo);
answerCount++;
answerGo.GetComponent<RotateAroundAnObject>().angle += angle;
angle += .1f;
yield return new WaitForSeconds(0.1f);
}
InvokeRepeating("GetAndRemoveBadAnswer", 7, 7F);
}
else
{
foreach (GetTheQuestions.Answer answer in theCurrentQuestion.Answers)
{
answerGo = PhotonNetwork.Instantiate(answerfab.name, launcher_Player2[answerCount].transform.position, Quaternion.Inverse(Quaternion.identity));
answerGo.GetComponent<TextMeshPro>().text = theCurrentQuestion.Answers[answerCount].Text + "_Sub";
answers.Add(answerGo);
answerCount++;
answerGo.GetComponent<RotateAroundAnObject>().angle += angle;
angle += .1f;
yield return new WaitForSeconds(0.1f);
}
InvokeRepeating("GetAndRemoveBadAnswer", 7, 7F);
}
}