Advertisement
GoodNoodle

CharecterSwap

Mar 21st, 2023
760
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Cinemachine;
  5.  
  6.  
  7. public class CharecterSwap : MonoBehaviour
  8. {
  9.  
  10.     public Transform charecter;
  11.     public List<Transform> charecterstoSwap;
  12.  
  13.     public int whichCharecter;
  14.  
  15.     public CinemachineVirtualCamera cam;
  16.  
  17.     public bool isInRange;
  18.     // Start is called before the first frame update
  19.     void Start()
  20.     {
  21.         if (charecter == null && charecterstoSwap.Count >= 1)
  22.         {
  23.             charecter = charecterstoSwap[0];
  24.         }
  25.         Swap();
  26.     }
  27.  
  28.     // Update is called once per frame
  29.     void Update()
  30.     {
  31.         if (Input.GetKeyDown(KeyCode.Tab))
  32.         {
  33.             if (whichCharecter == 0)
  34.             {
  35.                 whichCharecter = charecterstoSwap.Count - 1;
  36.             }
  37.  
  38.             else
  39.             {
  40.                 whichCharecter -= 1;
  41.             }
  42.             Swap();
  43.         }
  44.  
  45.         if (Input.GetKeyDown(KeyCode.LeftShift))
  46.         {
  47.             if (whichCharecter == charecterstoSwap.Count - 1)
  48.             {
  49.                 whichCharecter = 0;
  50.             }
  51.  
  52.             else
  53.             {
  54.                 whichCharecter += 1;
  55.             }
  56.             Swap();
  57.         }
  58.  
  59.  
  60.  
  61.     }
  62.  
  63.     public void Swap()
  64.     {
  65.         charecter = charecterstoSwap[whichCharecter];
  66.         charecter.GetComponent<PlayerController>().enabled = true;
  67.         charecter.GetComponent<Party>().enabled = true;
  68.  
  69.         for (int i = 0; i < charecterstoSwap.Count; i++)
  70.         {
  71.             if (charecterstoSwap[i] != charecter)
  72.             {
  73.                 charecter.GetComponent<PlayerController>().enabled = false;
  74.                 charecter.GetComponent<Party>().enabled = false;
  75.                 charecter.GetComponent<BuddyController>().enabled = true;
  76.             }
  77.         }
  78.        cam.LookAt = charecter;
  79.        cam.Follow= charecter;
  80.     }
  81.  
  82. }
  83.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement