You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using Networking.Server;
  6. using Networking;
  7. public class PortalSetup : MonoBehaviour
  8. {
  9. public ConnectionHandler clientDataList;
  10. public List<ClientData> ConnectedClients;
  11. public Color[] playerColours;
  12. public List<int> validIndex;
  13. public float collectAmount;
  14. public float waitTime;
  15. int currentIndex = 0;
  16. Color deactiveGrey = new Color32 (120, 120, 120, 255);
  17. Color deactiveGreyA = new Color32 (120, 120, 120, 0);
  18. bool collectedFive = false;
  19. //load portal
  20. public ParticleSystem Edge;
  21. public ParticleSystem InSpark;
  22. public ParticleSystem RandomSparks;
  23. public ParticleSystem Ring;
  24. public ParticleSystem Smoke;
  25. ParticleSystem.MainModule mainEdge;
  26. ParticleSystem.MainModule mainInSpark;
  27. ParticleSystem.MainModule mainRandomSparks;
  28. ParticleSystem.MainModule mainRing;
  29. ParticleSystem.MainModule mainSmoke;
  30. IEnumerator ColorChange ()
  31. {
  32. while(true){
  33. mainEdge.startColor = playerColours[validIndex[currentIndex]];
  34. mainInSpark.startColor = playerColours[validIndex[currentIndex]];
  35. mainRandomSparks.startColor = playerColours[validIndex[currentIndex]];
  36. mainRing.startColor = playerColours[validIndex[currentIndex]];
  37. mainSmoke.startColor = playerColours[validIndex[currentIndex]];
  38. currentIndex++;
  39. if(currentIndex >= validIndex.Count){
  40. currentIndex = 0;
  41. }
  42. yield return new WaitForSeconds (5.0f);
  43. }
  44. }
  45. void Update()
  46. {
  47. if (!collectedFive && (ConnectedClients[0].collected >= collectAmount || ConnectedClients[1].collected >= collectAmount || ConnectedClients[2].collected >= collectAmount || ConnectedClients[3].collected >= collectAmount)){
  48. collectedFive = true;
  49. StartCoroutine (ColorChange ());
  50. }
  51. }
  52. private void Awake ()
  53. {
  54. //get list of players
  55. ConnectedClients = clientDataList.ConnectedClients;
  56. playerColours = new Color[ConnectedClients.Count];
  57. validIndex = new List<int>();
  58. for (int i = 0; i < ConnectedClients.Count; i++){
  59. playerColours[i] = ConnectedClients[i].Color;
  60. }
  61. //link portal particle sections
  62. mainEdge = Edge.main;
  63. mainInSpark = InSpark.main;
  64. mainRandomSparks = RandomSparks.main;
  65. mainRing = Ring.main;
  66. mainSmoke = Smoke.main;
  67. //set start mode for portal
  68. mainEdge.startColor = deactiveGrey;
  69. mainInSpark.startColor = deactiveGreyA;
  70. mainRandomSparks.startColor = deactiveGreyA;
  71. mainRing.startColor = deactiveGrey;
  72. mainSmoke.startColor = deactiveGreyA;
  73. }
  74. }