mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
CHANGED TO MIRROR
This commit is contained in:
@@ -1,38 +1,119 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
public class Player : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] int health;
|
||||
[SerializeField] float SyncIntervalSeconds = 5.0f;
|
||||
[SerializeField] GameObject GameManager;
|
||||
|
||||
public bool isAlive;
|
||||
public Team team;
|
||||
[SerializeField] private const int defaultHp = 100;
|
||||
|
||||
private PlayerMaster playerMaster;
|
||||
public ulong clientId;
|
||||
private string name;
|
||||
private int health;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
|
||||
private void Start()
|
||||
|
||||
public void SetName(string newName)
|
||||
{
|
||||
GameManager = GameObject.Find("GameManager");
|
||||
playerMaster = GameManager.GetComponent<PlayerMaster>();
|
||||
|
||||
//InvokeRepeating("Sync", 3.0f, SyncIntervalSeconds);
|
||||
name = newName;
|
||||
}
|
||||
|
||||
|
||||
private void Sync()
|
||||
public string GetName()
|
||||
{
|
||||
Debug.Log("Sync");
|
||||
health = playerMaster.SyncHealth(gameObject);
|
||||
return name;
|
||||
}
|
||||
public void Respawn()
|
||||
{
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
public void SubstractHealth(int value)
|
||||
public void Die()
|
||||
{
|
||||
health -= value;
|
||||
isAlive = false;
|
||||
AddDeaths(1);
|
||||
}
|
||||
|
||||
//Health
|
||||
public void AddHealth(int value)
|
||||
{
|
||||
health += value;
|
||||
if (isAlive)
|
||||
{
|
||||
health += value;
|
||||
}
|
||||
|
||||
}
|
||||
public void RemoveHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health -= value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void SetHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health = value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetHealth()
|
||||
{
|
||||
return health;
|
||||
}
|
||||
|
||||
//Kills
|
||||
public void AddKills(int value)
|
||||
{
|
||||
kills += value;
|
||||
}
|
||||
public void RemoveKills(int value)
|
||||
{
|
||||
kills -= value;
|
||||
}
|
||||
public void SetKills(int value)
|
||||
{
|
||||
kills = value;
|
||||
}
|
||||
|
||||
public int GetKills()
|
||||
{
|
||||
return kills;
|
||||
}
|
||||
|
||||
//Deaths
|
||||
public void AddDeaths(int value)
|
||||
{
|
||||
deaths += value;
|
||||
}
|
||||
public void RemoveDeaths(int value)
|
||||
{
|
||||
deaths -= value;
|
||||
}
|
||||
public void SetDeaths(int value)
|
||||
{
|
||||
deaths = value;
|
||||
}
|
||||
|
||||
public int GetDeaths()
|
||||
{
|
||||
return deaths;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
using Mirror;
|
||||
|
||||
// https://youtu.be/PmIPqGqp8UY
|
||||
// https://youtu.be/n-KX8AeGK7E?t=997
|
||||
@@ -48,7 +48,7 @@ public class PlayerController : NetworkBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (IsLocalPlayer)
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
controller = GetComponent<CharacterController>();
|
||||
if (lockCursor)
|
||||
@@ -65,16 +65,11 @@ public class PlayerController : NetworkBehaviour
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (IsLocalPlayer)
|
||||
{
|
||||
UpdateMouseLook();
|
||||
Grounded();
|
||||
UpdateMovement();
|
||||
}
|
||||
else
|
||||
{
|
||||
playerCamera.gameObject.SetActive(false);
|
||||
}
|
||||
if (!isLocalPlayer) return;
|
||||
|
||||
UpdateMouseLook();
|
||||
Grounded();
|
||||
UpdateMovement();
|
||||
|
||||
}
|
||||
private void Grounded()
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
using MLAPI.NetworkVariable;
|
||||
using MLAPI.Transports;
|
||||
using MLAPI.Messaging;
|
||||
using TMPro;
|
||||
|
||||
public class PlayerNetworkingScript : NetworkBehaviour
|
||||
{
|
||||
public NetworkVariableInt dice = new NetworkVariableInt(new NetworkVariableSettings
|
||||
{
|
||||
WritePermission = NetworkVariablePermission.ServerOnly,
|
||||
ReadPermission = NetworkVariablePermission.Everyone
|
||||
});
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.J))
|
||||
{
|
||||
Debug.Log("J");
|
||||
NetworkManager.Singleton.StopHost();
|
||||
NetworkManager.Singleton.StartClient();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfd6cd3bbcb023440832d53f9f1f0041
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user