//When the player dies the game manager looks for the closest respawn point and teleports the player to that resapwn point // it also calls the UI Death effect public void Death() { GameObject[] SpawnPoints = GameObject.FindGameObjectsWithTag("RespawnPoint"); float ShortDistance = 1000f; int SavedIndex = 0; for (int i = 0; i < SpawnPoints.Length; i++) { if (Player != null) { if (Vector3.Distance(Player.transform.position, SpawnPoints[i].transform.position) < ShortDistance) { ShortDistance = Vector3.Distance(Player.transform.position, SpawnPoints[i].transform.position); SavedIndex = i; } } } UIM.CallDeathEffect(); Player.transform.position = SpawnPoints[SavedIndex].transform.position; }