Changing player collision system. Changing Input System. Completing Environemental Velocity Variation.

This commit is contained in:
Anonymous Raccoon
2018-03-10 21:35:31 +01:00
parent 07d3a82ac3
commit 1615b2d5c9
16 changed files with 1196 additions and 139 deletions
+37 -14
View File
@@ -7,23 +7,46 @@ public class LobbyPlayer : NetworkLobbyPlayer
{
base.OnClientEnterLobby();
NetworkManager netManager = GameObject.Find("GameManager").GetComponent<NetworkManager>();
if (!GetComponent<PlayerMovement>().setuped)
{
int playerNumber = 0;
NetworkManager netManager = GameObject.Find("GameManager").GetComponent<NetworkManager>();
if (netManager.ControllerP1 != 0 && GameObject.Find("LobbyPlayer (1)") == null)
playerNumber = 1;
if (netManager.ControllerP2 != 0 && GameObject.Find("LobbyPlayer (2)") == null)
playerNumber = 2;
if (netManager.ControllerP3 != 0 && GameObject.Find("LobbyPlayer (3)") == null)
playerNumber = 3;
if (netManager.ControllerP4 != 0 && GameObject.Find("LobbyPlayer (4)") == null)
playerNumber = 4;
int playerNumber = 0;
if (playerNumber == 0)
playerNumber = 1;
if (netManager.ControllerP1 != 0 && GameObject.Find("LobbyPlayer (1)") == null)
playerNumber = 1;
if (netManager.ControllerP2 != 0 && GameObject.Find("LobbyPlayer (2)") == null)
playerNumber = 2;
if (netManager.ControllerP3 != 0 && GameObject.Find("LobbyPlayer (3)") == null)
playerNumber = 3;
if (netManager.ControllerP4 != 0 && GameObject.Find("LobbyPlayer (4)") == null)
playerNumber = 4;
gameObject.name = "LobbyPlayer (" + playerNumber + ")";
netManager.SetupPlayerController(gameObject.GetComponent<PlayerMovement>(), playerNumber);
if (playerNumber == 0)
playerNumber = 1;
gameObject.name = "LobbyPlayer (" + playerNumber + ")";
netManager.SetupPlayerController(gameObject.GetComponent<PlayerMovement>(), playerNumber);
}
else
LobbyEntered();
}
private void LobbyEntered()
{
GetComponent<PlayerMovement>().enabled = true;
GetComponent<CapsuleCollider>().enabled = true;
GetComponent<MeshRenderer>().enabled = true;
transform.position = new Vector3(0, 2, 0);
GetComponent<Rigidbody>().velocity = new Vector3(0, 10, 0);
}
public void GameEntered()
{
GetComponent<PlayerMovement>().enabled = false;
GetComponent<CapsuleCollider>().enabled = false;
GetComponent<MeshRenderer>().enabled = false;
}
}
+28
View File
@@ -0,0 +1,28 @@
using UnityEngine;
public class MapGenerator : MonoBehaviour
{
[SerializeField] private Texture2D[] maps;
private Texture2D map;
private void Start()
{
if (GameObject.Find("GameManager").GetComponent<NetworkManager>().selectedMap != -1)
map = maps[GameObject.Find("GameManager").GetComponent<NetworkManager>().selectedMap];
else
map = maps[Random.Range(0, maps.Length)];
for(int x = 0; x < map.width; x++)
{
for(int y = 0; y < map.height; y++)
{
CreateTile(x, y);
}
}
}
private void CreateTile(int x, int y)
{
//Color pixelColor = map.GetPixel(x, y);
}
}
+13
View File
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 51f13a75a864d5f458c7093ff02b89ed
timeCreated: 1520445956
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+234 -3
View File
@@ -1,14 +1,75 @@
using UnityEngine;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class NetworkManager : NetworkLobbyManager
{
[Space]
[SerializeField] private bool gameIsRunning = false;
[Space]
public int ControllerP1;
public int ControllerP2;
public int ControllerP3;
public int ControllerP4;
[Space]
public int selectedMap;
[Space]
[SerializeField] internal bool isDead1 = false;
[SerializeField] internal bool isDead2 = false;
[SerializeField] internal bool isDead3 = false;
[SerializeField] internal bool isDead4 = false;
public bool IsDead1
{
get
{
return isDead1;
}
set
{
isDead1 = value;
PlayerDied(1);
}
}
public bool IsDead2
{
get
{
return isDead2;
}
set
{
isDead2 = value;
PlayerDied(2);
}
}
public bool IsDead3
{
get
{
return isDead3;
}
set
{
isDead3 = value;
PlayerDied(3);
}
}
public bool IsDead4
{
get
{
return isDead4;
}
set
{
isDead4 = value;
PlayerDied(4);
}
}
private void Start()
{
@@ -27,6 +88,9 @@ public class NetworkManager : NetworkLobbyManager
private void Update()
{
if (gameIsRunning)
return;
//Check if a new controller or a keyboard is used and add a player
if (Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetKeyDown(KeyCode.Space))
{
@@ -80,7 +144,31 @@ public class NetworkManager : NetworkLobbyManager
CheckControllerToRemove(Controller);
}
//Check for ready calls
if ((Input.GetKey(KeyCode.JoystickButton0) && Input.GetKey(KeyCode.JoystickButton4) && Input.GetKey(KeyCode.JoystickButton5)) || Input.GetKey(KeyCode.Return))
{
int Controller = 0;
if (Input.GetKey(KeyCode.Joystick1Button0) && Input.GetKey(KeyCode.Joystick1Button4) && Input.GetKey(KeyCode.Joystick1Button5))
Controller = 1;
if (Input.GetKey(KeyCode.Joystick2Button0) && Input.GetKey(KeyCode.Joystick2Button4) && Input.GetKey(KeyCode.Joystick2Button5))
Controller = 2;
if (Input.GetKey(KeyCode.Joystick3Button0) && Input.GetKey(KeyCode.Joystick3Button4) && Input.GetKey(KeyCode.Joystick3Button5))
Controller = 3;
if (Input.GetKey(KeyCode.Joystick4Button0) && Input.GetKey(KeyCode.Joystick4Button4) && Input.GetKey(KeyCode.Joystick4Button5))
Controller = 4;
if (Input.GetKey(KeyCode.Joystick5Button0) && Input.GetKey(KeyCode.Joystick5Button4) && Input.GetKey(KeyCode.Joystick5Button5))
Controller = 5;
if (Input.GetKey(KeyCode.Joystick6Button0) && Input.GetKey(KeyCode.Joystick6Button4) && Input.GetKey(KeyCode.Joystick6Button5))
Controller = 6;
if (Input.GetKey(KeyCode.Joystick7Button0) && Input.GetKey(KeyCode.Joystick7Button4) && Input.GetKey(KeyCode.Joystick7Button5))
Controller = 7;
if (Input.GetKey(KeyCode.Joystick8Button0) && Input.GetKey(KeyCode.Joystick8Button4) && Input.GetKey(KeyCode.Joystick8Button5))
Controller = 8;
if (Input.GetKeyDown(KeyCode.Return))
Controller = 9;
CheckControllerToSetReady(Controller);
}
}
private void CheckControllerToAdd(int Controller)
@@ -163,6 +251,38 @@ public class NetworkManager : NetworkLobbyManager
lobbyPlayer.RemovePlayer();
}
private void CheckControllerToSetReady(int Controller)
{
if (Controller == 0)
return;
if (Controller == ControllerP1 && !GameObject.Find("LobbyPlayer (1)").GetComponent<LobbyPlayer>().readyToBegin)
{
SetPlayerReady(1);
return;
}
if (Controller == ControllerP2 && !GameObject.Find("LobbyPlayer (2)").GetComponent<LobbyPlayer>().readyToBegin)
{
SetPlayerReady(2);
return;
}
if (Controller == ControllerP3 && !GameObject.Find("LobbyPlayer (3)").GetComponent<LobbyPlayer>().readyToBegin)
{
SetPlayerReady(3);
return;
}
if (Controller == ControllerP4 && !GameObject.Find("LobbyPlayer (4)").GetComponent<LobbyPlayer>().readyToBegin)
{
SetPlayerReady(4);
return;
}
}
private void SetPlayerReady(int player)
{
GameObject.Find("LobbyPlayer (" + player + ")").GetComponent<LobbyPlayer>().SendReadyToBeginMessage();
}
public void SetupPlayerController(PlayerMovement pMovement, int player)
{
if(player == 1)
@@ -173,12 +293,20 @@ public class NetworkManager : NetworkLobbyManager
if(ControllerP1 == 9)
{
pMovement.Horizontal = "Horizontal_Keyboard";
pMovement.Vertical = "Vertical_Keyboard";
pMovement.JumpKey = KeyCode.Space;
pMovement.HookKey = KeyCode.LeftShift;
pMovement.DashKey = KeyCode.LeftControl;
pMovement.UltKey = KeyCode.F;
}
else
{
pMovement.Horizontal = "Horizontal_J" + ControllerP1;
pMovement.Vertical = "Vertical_J" + ControllerP1;
pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP1 + "Button0");
pMovement.HookKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP1 + "Button2");
pMovement.DashKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP1 + "Button3");
pMovement.UltKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP1 + "Button1");
}
}
else if (player == 2)
@@ -189,12 +317,21 @@ public class NetworkManager : NetworkLobbyManager
if (ControllerP2 == 9)
{
pMovement.Horizontal = "Horizontal_Keyboard";
pMovement.Vertical = "Vertical_Keyboard";
pMovement.JumpKey = KeyCode.Space;
pMovement.HookKey = KeyCode.LeftShift;
pMovement.DashKey = KeyCode.LeftControl;
pMovement.UltKey = KeyCode.F;
}
else
{
pMovement.Horizontal = "Horizontal_J" + ControllerP2;
pMovement.Vertical = "Vertical_J" + ControllerP2;
pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP2 + "Button0");
pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP2 + "Button0");
pMovement.HookKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP2 + "Button2");
pMovement.DashKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP2 + "Button3");
pMovement.UltKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP2 + "Button1");
}
}
else if (player == 3)
@@ -205,12 +342,21 @@ public class NetworkManager : NetworkLobbyManager
if (ControllerP3 == 9)
{
pMovement.Horizontal = "Horizontal_Keyboard";
pMovement.Vertical = "Vertical_Keyboard";
pMovement.JumpKey = KeyCode.Space;
pMovement.HookKey = KeyCode.LeftShift;
pMovement.DashKey = KeyCode.LeftControl;
pMovement.UltKey = KeyCode.F;
}
else
{
pMovement.Horizontal = "Horizontal_J" + ControllerP3;
pMovement.Vertical = "Vertical_J" + ControllerP3;
pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP3 + "Button0");
pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP3 + "Button0");
pMovement.HookKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP3 + "Button2");
pMovement.DashKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP3 + "Button3");
pMovement.UltKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP3 + "Button1");
}
}
else if (player == 4)
@@ -221,16 +367,101 @@ public class NetworkManager : NetworkLobbyManager
if (ControllerP4 == 9)
{
pMovement.Horizontal = "Horizontal_Keyboard";
pMovement.Vertical = "Vertical_Keyboard";
pMovement.JumpKey = KeyCode.Space;
pMovement.HookKey = KeyCode.LeftShift;
pMovement.DashKey = KeyCode.LeftControl;
pMovement.UltKey = KeyCode.F;
}
else
{
pMovement.Horizontal = "Horizontal_J" + ControllerP4;
pMovement.Vertical = "Vertical_J" + ControllerP4;
pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP4 + "Button0");
pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP4 + "Button0");
pMovement.HookKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP4 + "Button2");
pMovement.DashKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP4 + "Button3");
pMovement.UltKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP4 + "Button1");
}
}
pMovement.gameObject.transform.position = new Vector3(0, 2, 0);
pMovement.gameObject.GetComponent<Rigidbody>().velocity = new Vector3(0, 10, 0);
pMovement.setuped = true;
pMovement.gameObject.transform.position = new Vector3(player * 2, 2, 0);
pMovement.gameObject.GetComponent<Rigidbody>().velocity = new Vector3(0, 5, 0);
}
public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
{
int playerNumber = int.Parse(lobbyPlayer.name.Substring(lobbyPlayer.name.IndexOf("(") + 1, 1));
gamePlayer.name = "GamePlayer (" + playerNumber + ")";
SetupPlayerController(gamePlayer.GetComponent<PlayerMovement>(), playerNumber);
lobbyPlayer.GetComponent<LobbyPlayer>().GameEntered();
return base.OnLobbyServerSceneLoadedForPlayer(lobbyPlayer, gamePlayer);
}
private void PlayerDied(int player)
{
int playerCount = 0;
if (ControllerP1 != 0)
playerCount++;
if (ControllerP2 != 0)
playerCount++;
if (ControllerP3 != 0)
playerCount++;
if (ControllerP4 != 0)
playerCount++;
int dieCount = 0;
if (IsDead1)
dieCount++;
if (IsDead2)
dieCount++;
if (IsDead3 && playerCount > 2)
dieCount++;
if (IsDead4 && playerCount > 3)
dieCount++;
if (dieCount >= playerCount)
{
ServerReturnToLobby();
}
else if (dieCount == playerCount - 1)
{
int playerAlive = 0;
if (!IsDead1)
playerAlive = 1;
if (!IsDead2)
playerAlive = 2;
if (!IsDead3 && playerCount > 2)
playerAlive = 3;
if (!IsDead4 && playerCount > 3)
playerAlive = 4;
//Win screen
print("Player " + playerAlive + " won!");
StartCoroutine("ReturnToLobby");
isDead1 = false;
isDead2 = false;
isDead3 = false;
isDead4 = false;
}
else
{
//Player is dead
print("Player " + player + " is dead.");
}
}
private IEnumerator ReturnToLobby()
{
yield return new WaitForSeconds(2.5f);
gameIsRunning = false;
ServerReturnToLobby();
}
}
+129 -39
View File
@@ -1,29 +1,48 @@
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMovement : MonoBehaviour
{
public string Horizontal;
public string Vertical;
public KeyCode JumpKey = KeyCode.None;
public KeyCode HookKey = KeyCode.None;
public KeyCode DashKey = KeyCode.None;
public KeyCode UltKey = KeyCode.None;
[Space]
[SerializeField] private int speed = 10;
[SerializeField] private int airSpeed = 5;
[SerializeField] private int airSpeed = 7;
[SerializeField] private int jumpForce = 8;
[SerializeField] private int smallJump = 4;
[SerializeField] private float gravity = 8.5f;
[SerializeField] private int wallJump = 200;
[SerializeField] private int wallJumpPush = 250;
[SerializeField] private float wallJumpSpeed;
[SerializeField] private float gravity = -10;
[SerializeField] private int wallJump = 4;
[SerializeField] private int wallJumpPush = 10;
[SerializeField] private int smallJumpPush = 5;
[SerializeField] private float pushSpeed = 0.2f;
[SerializeField] private float dashSpeed = 15;
[Space]
[SerializeField] private LayerMask wallMask;
[SerializeField] private GameObject smallProjectile;
[Space]
[Space]
[SerializeField] private LayerMask playerMask;
[Space]
public bool setuped = false;
private float velocity = 0;
private bool groundedLastFrame = false;
private int wallDirection;
private int wallJumpTimer = 0;
private bool wallJumped;
private float jumpDirection;
private MovingElement movingPlateform;
private Rigidbody rb;
@@ -55,8 +74,18 @@ public class PlayerMovement : MonoBehaviour
private bool IsSliding()
{
Collider[] walls = Physics.OverlapSphere(rb.position, 1, wallMask);
if (walls.Length > 0)
CapsuleCollider col = GetComponent<CapsuleCollider>();
List<RaycastHit> raycastHits = Physics.BoxCastAll(rb.position - new Vector3(0, 0.6f, 0), new Vector3(0.55f, 0, 1), Vector3.up, Quaternion.identity, 1.2f).ToList();
List<RaycastHit> walls = new List<RaycastHit>();
foreach(RaycastHit hit in raycastHits)
{
if (hit.collider.tag != "Player")
walls.Add(hit);
}
if (walls.Count > 0)
{
wallJumpTimer = 10;
@@ -75,6 +104,30 @@ public class PlayerMovement : MonoBehaviour
return false;
}
private bool IsPushing()
{
List<RaycastHit> raycastHits = Physics.BoxCastAll(rb.position - new Vector3(0, 0.6f, 0), new Vector3(0.55f, 0, 1), Vector3.up, Quaternion.identity, 1.2f, playerMask).ToList();
List<RaycastHit> players = new List<RaycastHit>();
foreach (RaycastHit hit in raycastHits)
{
if (hit.collider.gameObject != gameObject)
players.Add(hit);
}
if (players.Count > 0)
{
for (int i = 0; i < players.Count; i++)
{
if (players[i].transform.position.x > rb.position.x && Input.GetAxis(Horizontal) > 0)
return true;
else if (players[i].transform.position.x < rb.position.x && Input.GetAxis(Horizontal) < 0)
return true;
}
}
return false;
}
private bool AirControl(bool isGrounded)
{
if (!isGrounded)
@@ -126,55 +179,59 @@ public class PlayerMovement : MonoBehaviour
bool isGrounded = IsGrounded();
bool isSliding = IsSliding();
bool isPushing = IsPushing();
bool airControl = AirControl(isGrounded);
//Check if we have left the plateform
if (movingPlateform != null && !isGrounded && !groundedLastFrame && !isSliding)
movingPlateform = null;
//Move user with horizontal axis input
if (!isSliding)
if (-1 < velocity && velocity < 1)
velocity = 0;
if (velocity > 0)
velocity -= 0.5f;
else if (velocity < 0)
velocity += 0.5f;
float horizontalVel = Input.GetAxis(Horizontal);
if (wallJumped)
{
if(!wallJumped)
rb.AddForce(new Vector3(Input.GetAxis(Horizontal) * (airControl ? airSpeed : speed) - rb.velocity.x, 0, 0), ForceMode.Impulse);
else
{
if(jumpDirection > 0 && Input.GetAxis(Horizontal) > 0)
{
//good direction
rb.AddForce(new Vector3(Input.GetAxis(Horizontal) * airSpeed / 2 - rb.velocity.x, 0, 0), ForceMode.Impulse);
}
else if(jumpDirection > 0 && Input.GetAxis(Horizontal) < 0)
{
//reverse direction
rb.AddForce(new Vector3(Input.GetAxis(Horizontal) * airSpeed - rb.velocity.x, 0, 0), ForceMode.Acceleration);
}
else if(jumpDirection < 0 && Input.GetAxis(Horizontal) > 0)
{
//reverse direction
rb.AddForce(new Vector3(Input.GetAxis(Horizontal) * airSpeed - rb.velocity.x, 0, 0), ForceMode.Acceleration);
}
else if(jumpDirection < 0 && Input.GetAxis(Horizontal) < 0)
{
//good direction
rb.AddForce(new Vector3(Input.GetAxis(Horizontal) * airSpeed / 2 - rb.velocity.x, 0, 0), ForceMode.Impulse);
}
}
if (-0.3 < horizontalVel && horizontalVel < 0.3)
horizontalVel = 0.6f * jumpDirection;
if (Mathf.Sign(horizontalVel) == Mathf.Sign(horizontalVel))
horizontalVel /= 2;
}
if(!isSliding || (isSliding && Mathf.Sign(wallDirection) != Mathf.Sign(Input.GetAxis(Horizontal))))
rb.AddForce(new Vector3(horizontalVel * (isPushing ? pushSpeed : 1) * (airControl ? airSpeed : speed) - (rb.velocity.x - velocity), 0, 0), ForceMode.Impulse);
//Make user jump
if (Input.GetKeyDown(JumpKey) && isGrounded)
if (Input.GetKey(JumpKey) && isGrounded)
{
jumpDirection = Input.GetAxis(Horizontal);
rb.velocity = new Vector3(rb.velocity.x, jumpForce + (movingPlateform != null ? movingPlateform.rb.velocity.y : 0) , rb.velocity.z);
}
//Make a small jump if user drop the button
if (Input.GetKeyUp(JumpKey) && !isGrounded && rb.velocity.y > smallJump && !wallJumped)
rb.velocity = new Vector3(rb.velocity.x, smallJump, rb.velocity.z);
if (Input.GetKeyUp(JumpKey) && !isGrounded && rb.velocity.y > smallJump)
{
if(wallJumped && Mathf.Abs(rb.velocity.x) > smallJumpPush)
{
velocity = smallJumpPush * jumpDirection;
rb.velocity = new Vector3(rb.velocity.x - (wallJumpPush - smallJumpPush) * jumpDirection, rb.velocity.y, rb.velocity.z);
}
else
rb.velocity = new Vector3(rb.velocity.x, smallJump, rb.velocity.z);
}
//Move with the plateform
if (movingPlateform != null)
{
rb.AddForce(new Vector3(movingPlateform.rb.velocity.x, 0, 0), ForceMode.Impulse);
}
//Apply more gravity
if (rb.velocity.y < 1 && !isSliding)
@@ -188,10 +245,43 @@ public class PlayerMovement : MonoBehaviour
{
wallJumped = true;
jumpDirection = -wallDirection;
velocity = wallJumpPush * jumpDirection;
rb.AddForce(new Vector3(wallJumpPush * jumpDirection, wallJump, 0), ForceMode.Impulse);
}
else if(isSliding)
rb.AddForce(new Vector3(0, Mathf.Abs(rb.velocity.y) + gravity / 3, 0), ForceMode.Acceleration);
rb.AddForce(new Vector3(0, Mathf.Abs(rb.velocity.y) + gravity / 2, 0), ForceMode.Acceleration);
}
//Dash and small attack
if (Input.GetKeyDown(DashKey))
{
horizontalVel = Input.GetAxis(Horizontal);
float verticalVel = Input.GetAxis(Vertical);
//if(horizontalVel ) //if horizontal and vertical vel are null, set horizontal to 0.80
rb.velocity = new Vector3(dashSpeed * horizontalVel, dashSpeed * verticalVel, 0);
velocity = dashSpeed * Input.GetAxis(Horizontal);
//Instantiate(smallProjectile, rb.position)
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "DeathZone")
Die();
}
private void Die()
{
if (gameObject.name == "GamePlayer (1)")
GameObject.Find("GameManager").GetComponent<NetworkManager>().IsDead1 = true;
if (gameObject.name == "GamePlayer (2)")
GameObject.Find("GameManager").GetComponent<NetworkManager>().IsDead2 = true;
if (gameObject.name == "GamePlayer (3)")
GameObject.Find("GameManager").GetComponent<NetworkManager>().IsDead3 = true;
if (gameObject.name == "GamePlayer (4)")
GameObject.Find("GameManager").GetComponent<NetworkManager>().IsDead4 = true;
}
}