Advertisement
dronkowitz

TeamSetup.cs

Mar 24th, 2021 (edited)
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TeamSetup : MonoBehaviour
  6. {
  7.     public TeamComposition CurrentTeam;
  8.     public GameObject pos1;
  9.     public GameObject pos2;
  10.     public Transform leftTeamMember;
  11.     public Transform rightTeamMember;
  12.     public Transform player;
  13.     public GameObject HUD;
  14.     private Coroutine superFormRingCountdown;
  15.  
  16.  
  17.  
  18.     public static TeamSetup pc;
  19.  
  20.     // Start is called before the first frame update
  21.     void Start()
  22.     {
  23.         pc = this;
  24.         //Setup Player
  25.         Transform body = Instantiate(CurrentTeam.SpeedCharacter, player).transform;
  26.         GetComponent<CharacterSwitch>().speedCharacter = body;
  27.         body.localPosition = Vector3.zero;
  28.         body.localRotation = Quaternion.identity;
  29.         CharacterSwitch switcher = GetComponent<CharacterSwitch>();
  30.         player.GetComponent<UltimatePlayerMovement>().SetupAnimation();
  31.  
  32.         switcher.TeamMembers.Add(body.gameObject);
  33.  
  34.         //Setup Left Team Member
  35.         GameObject ai = Instantiate(CurrentTeam.FlyingCharacter, leftTeamMember);
  36.         GetComponent<CharacterSwitch>().flyingCharacter = ai.transform;
  37.         ai.transform.localPosition = Vector3.zero;
  38.         ai.transform.localRotation = Quaternion.identity;
  39.         switcher.TeamMembers.Add(ai);
  40.         leftTeamMember.GetComponent<FollowerNavigation>().Setup();
  41.  
  42.         //Setup Right Team Member
  43.         ai = Instantiate(CurrentTeam.PowerCharacter, rightTeamMember);
  44.         GetComponent<CharacterSwitch>().powerCharacter = ai.transform;
  45.         ai.transform.localPosition = Vector3.zero;
  46.         ai.transform.localRotation = Quaternion.identity;
  47.         switcher.TeamMembers.Add(ai);
  48.         rightTeamMember.GetComponent<FollowerNavigation>().Setup();
  49.  
  50.  
  51.         player.parent = null;
  52.         leftTeamMember.parent = null;
  53.         rightTeamMember.parent = null;
  54.  
  55.         HUD = FindObjectOfType<HUD>().gameObject;
  56.         HUD.GetComponent<HUD>().Setup(CurrentTeam);
  57.         if (CurrentTeam.name == "Team Sonic")
  58.         {
  59.             GameInstance.currentTeam = 0;
  60.         }
  61.         if (CurrentTeam.name == "Team Dark")
  62.         {
  63.             GameInstance.currentTeam = 1;
  64.         }
  65.         if (CurrentTeam.name == "Team Rose")
  66.         {
  67.             GameInstance.currentTeam = 2;
  68.         }
  69.         if (CurrentTeam.name == "Team Chaotix")
  70.         {
  71.             GameInstance.currentTeam = 3;
  72.         }
  73.     }
  74.  
  75.     // Update is called once per frame
  76.     void Update()
  77.     {
  78.  
  79.     }
  80.     public void SwapForSuper()
  81.     {
  82.         CharacterSwitch switcher = GetComponent<CharacterSwitch>();
  83.         Transform SpeedCharacter = GetComponent<CharacterSwitch>().speedCharacter;
  84.         switcher.TeamMembers.Remove(SpeedCharacter.gameObject);
  85.         Destroy(SpeedCharacter.gameObject);
  86.  
  87.         Transform body = Instantiate(CurrentTeam.SuperCharacter, player).transform;
  88.         GetComponent<CharacterSwitch>().speedCharacter = body;
  89.         body.localPosition = Vector3.zero;
  90.         body.localRotation = Quaternion.identity;
  91.  
  92.         switcher.TeamMembers.Add(body.gameObject);
  93.         superFormRingCountdown = StartCoroutine(SuperCountDown());
  94.        
  95.     }
  96.     public IEnumerator SuperCountDown()
  97.     {
  98.         while(GameInstance.currentRings > 0)
  99.         {
  100.             HUD.GetComponent<HUD>().UpdateRings();
  101.             GameInstance.currentRings -= 1;
  102.             yield return new WaitForSeconds(3);
  103.         }
  104.  
  105.         superFormRingCountdown = null;
  106.         SwapForSonic();
  107.     }
  108.     public void SwapForSonic()
  109.     {
  110.         if (superFormRingCountdown != null)
  111.         {
  112.             StopCoroutine(superFormRingCountdown);
  113.             superFormRingCountdown = null;
  114.         }
  115.         HUD.GetComponent<HUD>().UpdateRings();
  116.         CharacterSwitch switcher = GetComponent<CharacterSwitch>();
  117.         Transform SpeedCharacter = GetComponent<CharacterSwitch>().speedCharacter;
  118.         switcher.TeamMembers.Remove(SpeedCharacter.gameObject);
  119.         Destroy(SpeedCharacter.gameObject);
  120.  
  121.         Transform body = Instantiate(CurrentTeam.SpeedCharacter, player).transform;
  122.         GetComponent<CharacterSwitch>().speedCharacter = body;
  123.         body.localPosition = Vector3.zero;
  124.         body.localRotation = Quaternion.identity;
  125.  
  126.         switcher.TeamMembers.Add(body.gameObject);
  127.     }
  128. }
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement