0

Возникла проблема - я делаю мультиплеерную мини-игру футбола. Но проблема в том, что когда кто-то забивает мяч, гол может засчитаться 2-3 раза и из-за этого ломается пол игры. Я подозреваю, что дело тут в RPC.

public void OnCollisionEnter(Collision other)
{
    if (other.collider.CompareTag("Left Vorota"))
    {
        Debug.Log("Ball lefted");
        SendRpcLeft();
    }
    if (other.collider.CompareTag("Right Vorota"))
    {
        Debug.Log("Ball righted");
        SendRpcRight();
    }
}

void SendRpcRight()
{
    photonView.RPC("Send_Data_Right", RpcTarget.AllViaServer, count1, count2);
}
void SendRpcLeft()
{
    photonView.RPC("Send_Data_Left", RpcTarget.AllViaServer, count1, count2);
}

[PunRPC]
void Send_Data_Right(int counting1, int counting2)
{
    counting1 = counting1 + 1;
    count1 = counting1;
    finalCounting = counting1 + ":" + counting2;
    counttext.text = finalCounting;
    ReloadScene();
}

[PunRPC]
void Send_Data_Left(int counting1, int counting2)
{
    counting2 = counting2 + 1;
    count2 = counting2;
    finalCounting = counting1 + ":" + counting2;
    counttext.text = finalCounting;
    ReloadScene();
}

private void ReloadScene()
{
    PhotonNetwork.AutomaticallySyncScene = true;
    PlayerPrefs.SetString("countText", counttext.text);
    PlayerPrefs.SetInt("countValue1", count1);
    PlayerPrefs.SetInt("countValue2", count2);
    PlayerPrefsX.SetBool("RocketCanFlyRace", true);
    PhotonNetwork.LoadLevel("MPRoomSoccer");
}
1
  • 1
    Наверное потому что каждый клиент нашел свою коллизию с воротами и все отправили "Гол!"
    – aepot
    28 ноя 2022 в 9:43

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.