Здравствуйте, у меня проблема с нерестом, когда я запускаю службу Google RealTime, оба игрока отстают, а один игрок прослушивается в наземном коллайдере.Анимация:
Анимация
Вот мой сценарий отправки от клиента:
void Update()
{
if (player == PlayerOne) {
string PlayerOneData = "PlayerOne" + ":" + player.transform.position.x + ":" + player.transform.position.y;
byte[] PlayerOneDataArr = System.Text.ASCIIEncoding.Default.GetBytes(PlayerOneData);
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false, PlayerOneDataArr);
// Camera.main.GetComponent<CameraFollow>().setTarget(PlayerOne.transform);
textik.text = "PlayerOne upload " + PlayerOneData;
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Vector2 touchPosition = Input.GetTouch(0).position;
double halfScreen = Screen.width / 2.0;
if (touchPosition.x < halfScreen)
{
player.transform.Translate(Vector3.left * 10 * Time.deltaTime);
}
else if (touchPosition.x > halfScreen)
{
player.transform.Translate(Vector3.right * 10 * Time.deltaTime);
}
}
}
else if (player == PlayerTwo)
{
string PlayerTwoData = "PlayerTwo" + ":" + player.transform.position.x + ":" + player.transform.position.y;
byte[] PlayerTwoDataArr = System.Text.ASCIIEncoding.Default.GetBytes(PlayerTwoData);
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false, PlayerTwoDataArr);
//Camera.main.GetComponent<CameraFollow>().setTarget(PlayerTwo.transform);
textik.text = "PlayerTwo upload" + PlayerTwoData;
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Vector2 touchPosition = Input.GetTouch(0).position;
double halfScreen = Screen.width / 2.0;
//Check if it is left or right?
if (touchPosition.x < halfScreen)
{
player.transform.Translate(Vector3.left * 10 * Time.deltaTime);
}
else if (touchPosition.x > halfScreen)
{
player.transform.Translate(Vector3.right * 10 * Time.deltaTime);
}
}
}
}
И это моя функция получения:
public void OnRealTimeMessageReceived(bool IsReliable, string SenderId, byte[] data)
{
string position = System.Text.Encoding.Default.GetString(data);
string[] raw = position.Split(new string[] { ":" }, System.StringSplitOptions.RemoveEmptyEntries);
if (!IsReliable)
{
if (raw[0] == "PlayerOne")
{
PlayerOne.transform.position = new Vector2(System.Convert.ToSingle(raw[1]), System.Convert.ToSingle(raw[2]));
textik2.text = "PlayerOne PRIJAL " + position;
}
if (raw[0] == "PlayerTwo")
{
PlayerTwo.transform.position=new Vector2(System.Convert.ToSingle(raw[1]), System.Convert.ToSingle(raw[2]));
textik2.text = "PlayerTWO prijal " + position;
}
}
}
Мой сборник настроен как:
Сборный экран
Спасибо за любые идеи или любую помощь