dronkowitz

CharacterSwitch.cs

Mar 29th, 2021 (edited)
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.96 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CharacterSwitch : MonoBehaviour
  6. {
  7.     public List<GameObject> TeamMembers = new List<GameObject>();
  8.     public CHARACTERTYPES currentCharacterType = CHARACTERTYPES.Speed;
  9.     public Transform player, leftSlot, rightSlot;
  10.     public Transform speedCharacter, powerCharacter, flyingCharacter;
  11.     public GameObject superSonic;
  12.     public GameObject sonic;
  13.  
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.  
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.         if (Input.GetKeyDown(KeyCode.LeftBracket))
  24.         {
  25.             LeftCharacter();
  26.         }
  27.         if (Input.GetKeyDown(KeyCode.RightBracket))
  28.         {
  29.             RightCharacter();
  30.         }
  31.  
  32.         if (Input.GetKeyDown(KeyCode.Home))
  33.         {
  34.             ChangeSuper();
  35.            
  36.         }
  37.     }
  38.  
  39.     public void LeftCharacter()
  40.     {
  41.  
  42.  
  43.         switch (currentCharacterType)
  44.         {
  45.             case CHARACTERTYPES.Speed:
  46.                 currentCharacterType = CHARACTERTYPES.Fly;
  47.                 flyingCharacter.parent = player;
  48.                 powerCharacter.parent = leftSlot;
  49.                 speedCharacter.parent = rightSlot;
  50.                 break;
  51.             case CHARACTERTYPES.Fly:
  52.                 currentCharacterType = CHARACTERTYPES.Power;
  53.                 powerCharacter.parent = player;
  54.                 speedCharacter.parent = leftSlot;
  55.                 flyingCharacter.parent = rightSlot;
  56.                 break;
  57.             case CHARACTERTYPES.Power:
  58.                 currentCharacterType = CHARACTERTYPES.Speed;
  59.                 speedCharacter.parent = player;
  60.                 flyingCharacter.parent = leftSlot;
  61.                 powerCharacter.parent = rightSlot;
  62.                 break;
  63.         }
  64.         FindObjectOfType<HUD>().SetCharacter(-1);
  65.         ResetCharacters();
  66.     }
  67.  
  68.     public void RightCharacter()
  69.     {
  70.         switch (currentCharacterType)
  71.         {
  72.             case CHARACTERTYPES.Power:
  73.                 currentCharacterType = CHARACTERTYPES.Fly;
  74.                 flyingCharacter.parent = player;
  75.                 powerCharacter.parent = leftSlot;
  76.                 speedCharacter.parent = rightSlot;
  77.                 break;
  78.             case CHARACTERTYPES.Speed:
  79.                 currentCharacterType = CHARACTERTYPES.Power;
  80.                 powerCharacter.parent = player;
  81.                 speedCharacter.parent = leftSlot;
  82.                 flyingCharacter.parent = rightSlot;
  83.                 break;
  84.             case CHARACTERTYPES.Fly:
  85.                 currentCharacterType = CHARACTERTYPES.Speed;
  86.                 speedCharacter.parent = player;
  87.                 flyingCharacter.parent = leftSlot;
  88.                 powerCharacter.parent = rightSlot;
  89.                 break;
  90.         }
  91.         FindObjectOfType<HUD>().SetCharacter(1);
  92.         ResetCharacters();
  93.     }
  94.  
  95.     public void SetCharacter(CHARACTERTYPES newType)
  96.     {
  97.         currentCharacterType = newType;
  98.         switch (currentCharacterType)
  99.         {
  100.             case CHARACTERTYPES.Fly:
  101.                 currentCharacterType = CHARACTERTYPES.Fly;
  102.                 flyingCharacter.parent = player;
  103.                 powerCharacter.parent = leftSlot;
  104.                 speedCharacter.parent = rightSlot;
  105.                 break;
  106.             case CHARACTERTYPES.Power:
  107.                 currentCharacterType = CHARACTERTYPES.Power;
  108.                 powerCharacter.parent = player;
  109.                 speedCharacter.parent = leftSlot;
  110.                 flyingCharacter.parent = rightSlot;
  111.                 break;
  112.             case CHARACTERTYPES.Speed:
  113.                 currentCharacterType = CHARACTERTYPES.Speed;
  114.                 speedCharacter.parent = player;
  115.                 flyingCharacter.parent = leftSlot;
  116.                 powerCharacter.parent = rightSlot;
  117.                 break;
  118.         }
  119.         FindObjectOfType<HUD>().SetCharacter(currentCharacterType);
  120.         ResetCharacters();
  121.     }
  122.  
  123.     public void ResetCharacters()
  124.     {
  125.         speedCharacter.localPosition = Vector3.zero;
  126.         speedCharacter.localRotation = Quaternion.identity;
  127.  
  128.         flyingCharacter.localPosition = Vector3.zero;
  129.         flyingCharacter.localRotation = Quaternion.identity;
  130.  
  131.         powerCharacter.localPosition = Vector3.zero;
  132.         powerCharacter.localRotation = Quaternion.identity;
  133.  
  134.  
  135.     }
  136.  
  137.    
  138.  
  139.     public void ChangeSuper()
  140.     {
  141.         if (speedCharacter.name == "Sonic the Hedgehog(Clone)")
  142.         {
  143.             Destroy(speedCharacter.gameObject);
  144.             speedCharacter = Instantiate(superSonic, player).transform;
  145.             GetComponent<TeamSetup>().SwapForSuper();
  146.         }
  147.  
  148.         else if (speedCharacter.name == "Super Sonic(Clone)")
  149.         {
  150.             Destroy(speedCharacter.gameObject);
  151.             speedCharacter = Instantiate(sonic, player).transform;
  152.             GetComponent<TeamSetup>().SwapForSonic();
  153.         }
  154.     }
  155. }
  156.  
Add Comment
Please, Sign In to add comment