Dead Sync and Timescale Bug Fix

This commit is contained in:
brausjonas
2022-05-16 00:41:42 +02:00
parent c48efb161a
commit 2da20b9d79
4 changed files with 20 additions and 8 deletions
@@ -254,6 +254,11 @@ public class Client
Send(new byte[] { 3, (byte)chunk.x, (byte)chunk.z, xInChunk, yInChunk, zInChunk, blockID });
}
public void SendDeadMessage()
{
Send(new byte[]{10});
}
//default send method
private void Send(byte[] data)
{
@@ -149,7 +149,10 @@ public class Player : MonoBehaviour
if (transform.position.y < 0)
{
world.ShowDeadScreen();
if(Time.timeScale > 0)
{
world.ShowDeadScreen();
}
}
if (Input.GetKeyDown(KeyCode.Escape))
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -154,7 +155,7 @@ public class World : MonoBehaviour
//returns if a block is on the position
public bool CheckBlock(Vector3 positionInWorld)
{
if (positionInWorld.x < -1 || positionInWorld.z < -1 ||
if (positionInWorld.x < 0 || positionInWorld.z < 0 ||
positionInWorld.x > worldSize * Data.chunkWidth ||
positionInWorld.z > worldSize * Data.chunkWidth)
{
@@ -255,12 +256,6 @@ public class World : MonoBehaviour
client.Disconnect();
}
public void BackToMenu()
{
SceneManager.LoadScene("Scenes/Login", LoadSceneMode.Single);
}
public Client GetClient()
{
return client;
@@ -277,6 +272,7 @@ public class World : MonoBehaviour
public void ShowDeadScreen()
{
client.SendDeadMessage();
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
deadScreen.SetActive(true);
@@ -310,6 +306,7 @@ public class World : MonoBehaviour
public void QuitButton()
{
Time.timeScale = 1;
client.Disconnect();
SceneManager.LoadScene("Login");
deadScreen.SetActive(false);
+7
View File
@@ -47,6 +47,7 @@ public class Server
//[0] = 7: player position update
//[0] = 8: player rotation update
//[0] = 9: Save the World
//[0] = 10: Player died
private void Receive()
{
@@ -249,6 +250,12 @@ public class Server
{
world.SaveWorld();
}
//player died
if (data[0] == 10)
{
Console.WriteLine(playerNames[GetPlayerID(endPoint)] + " died!");
}
}
catch (Exception e)
{