Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Cinemachine;
- public class CharecterSwap : MonoBehaviour
- {
- public Transform charecter;
- public List<Transform> charecterstoSwap;
- public int whichCharecter;
- public CinemachineVirtualCamera cam;
- public bool isInRange;
- // Start is called before the first frame update
- void Start()
- {
- if (charecter == null && charecterstoSwap.Count >= 1)
- {
- charecter = charecterstoSwap[0];
- }
- Swap();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Tab))
- {
- if (whichCharecter == 0)
- {
- whichCharecter = charecterstoSwap.Count - 1;
- }
- else
- {
- whichCharecter -= 1;
- }
- Swap();
- }
- if (Input.GetKeyDown(KeyCode.LeftShift))
- {
- if (whichCharecter == charecterstoSwap.Count - 1)
- {
- whichCharecter = 0;
- }
- else
- {
- whichCharecter += 1;
- }
- Swap();
- }
- }
- public void Swap()
- {
- charecter = charecterstoSwap[whichCharecter];
- charecter.GetComponent<PlayerController>().enabled = true;
- charecter.GetComponent<Party>().enabled = true;
- for (int i = 0; i < charecterstoSwap.Count; i++)
- {
- if (charecterstoSwap[i] != charecter)
- {
- charecter.GetComponent<PlayerController>().enabled = false;
- charecter.GetComponent<Party>().enabled = false;
- charecter.GetComponent<BuddyController>().enabled = true;
- }
- }
- cam.LookAt = charecter;
- cam.Follow= charecter;
- }
- }
Advertisement
Advertisement