Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Mirror;
  5.  
  6. public class TurnSystem : NetworkBehaviour
  7. {
  8.  
  9.     public List<TurnClass> playersGroup;
  10.  
  11.     public GameObject[] players;
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         RpcResetTurns();
  17.         StartCoroutine(AddPlayersToList());
  18.     }
  19.  
  20.     IEnumerator AddPlayersToList()
  21.     {
  22.         yield return new WaitForSeconds(1f);
  23.  
  24.         RpcAddPlayers();
  25.     }
  26.  
  27.     [ClientRpc]
  28.     public void RpcAddPlayers()
  29.     {
  30.         players = GameObject.FindGameObjectsWithTag("Player");
  31.         for (int i = 0; i < players.Length; i++)
  32.         {
  33.             playersGroup.Add(players[i].GetComponent<PlayerMoveTurn>().turnClass);
  34.             playersGroup[i].player = players[i];
  35.         }
  36.  
  37.         RpcUpdateTurns();
  38.     }
  39.  
  40.     // Update is called once per frame
  41.     void Update()
  42.     {
  43.         RpcUpdateTurns();
  44.     }
  45.  
  46.     [ClientRpc]
  47.     void RpcResetTurns()
  48.     {
  49.         for (int i = 0; i < playersGroup.Count; i++)
  50.         {
  51.             if (i == 0)
  52.             {
  53.                 playersGroup[i].player.GetComponent<PlayerMoveTurn>().isTurn = true;
  54.                 playersGroup[i].player.GetComponent<PlayerMoveTurn>().actionPoints = 2;
  55.                 playersGroup[i].player.GetComponent<PlayerMoveTurn>().wasTurnPrev = false;
  56.             }
  57.             else
  58.             {
  59.                 playersGroup[i].player.GetComponent<PlayerMoveTurn>().isTurn = false;
  60.                 playersGroup[i].player.GetComponent<PlayerMoveTurn>().wasTurnPrev = false;
  61.             }
  62.         }
  63.     }
  64.  
  65.     [ClientRpc]
  66.     public void RpcUpdateTurns()
  67.     {
  68.         for (int i = 0; i < playersGroup.Count; i++)
  69.         {
  70.             if(!playersGroup[i].player.GetComponent<PlayerMoveTurn>().wasTurnPrev)
  71.             {
  72.                 playersGroup[i].player.GetComponent<PlayerMoveTurn>().isTurn = true;
  73.                 break;
  74.             }
  75.             else if(i == playersGroup.Count - 1 && playersGroup[i].player.GetComponent<PlayerMoveTurn>().wasTurnPrev)
  76.             {
  77.                 RpcResetTurns();
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. [System.Serializable]
  84. public class TurnClass
  85. {
  86.     public GameObject player;
  87.     //public bool isTurn = false;
  88.     //public bool wasTurnPrev = false;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement