Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 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.         StartCoroutine(AddPlayersToList());
  17.         RpcResetTurns();
  18.     }
  19.  
  20.     [Command]
  21.     void CmdResetTurn()
  22.     {
  23.         RpcResetTurns();
  24.     }
  25.  
  26.     IEnumerator AddPlayersToList()
  27.     {
  28.         yield return new WaitForSeconds(1f);
  29.  
  30.         RpcAddPlayers();
  31.     }
  32.  
  33.     [Command]
  34.     void CmdAddPlayers()
  35.     {
  36.         RpcAddPlayers();
  37.     }
  38.  
  39.     [ClientRpc]
  40.     public void RpcAddPlayers()
  41.     {
  42.         players = GameObject.FindGameObjectsWithTag("Player");
  43.         for (int i = 0; i < players.Length; i++)
  44.         {
  45.             playersGroup.Add(players[i].GetComponent<PlayerMoveTurn>().turnClass);
  46.             playersGroup[i].player = players[i];
  47.         }
  48.  
  49.         RpcUpdateTurns();
  50.     }
  51.  
  52.     [Command]
  53.     void CmdUpdateTurns()
  54.     {
  55.         RpcUpdateTurns();
  56.     }
  57.  
  58.     [ClientRpc]
  59.     void RpcResetTurns()
  60.     {
  61.         for (int i = 0; i < playersGroup.Count; i++)
  62.         {
  63.             if (i == 0)
  64.             {
  65.                 playersGroup[i].isTurn = true;
  66.                 playersGroup[i].actionPoints = 2;
  67.                 playersGroup[i].wasTurnPrev = false;
  68.             }
  69.             else
  70.             {
  71.                 playersGroup[i].isTurn = false;
  72.                 playersGroup[i].wasTurnPrev = false;
  73.             }
  74.         }
  75.     }
  76.  
  77.     [ClientRpc]
  78.     public void RpcUpdateTurns()
  79.     {
  80.         for (int i = 0; i < playersGroup.Count; i++)
  81.         {
  82.             if(!playersGroup[i].wasTurnPrev)
  83.             {
  84.                 playersGroup[i].isTurn = true;
  85.                 break;
  86.             }
  87.             else if(i == playersGroup.Count - 1 && playersGroup[i].wasTurnPrev)
  88.             {
  89.                 RpcResetTurns();
  90.             }
  91.         }
  92.     }
  93. }
  94.  
  95. [System.Serializable]
  96. public class TurnClass
  97. {
  98.     public GameObject player;
  99.     public int actionPoints = 2;
  100.     public bool isTurn = false;
  101.     public bool wasTurnPrev = false;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement