Advertisement
GoodNoodle

Buddy Controller

Sep 26th, 2023
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.TextCore.Text;
  5.  
  6. public class BuddyController : MonoBehaviour, ISwitchable
  7. {
  8.     private Charecter charecter;
  9.  
  10.     [SerializeField] private PlayerController player;
  11.    
  12.     public static BuddyController instance;
  13.  
  14.     [SerializeField] public DeathZone theZone;
  15.  
  16.     public bool isActive { get; set; }
  17.  
  18.     private void Awake()
  19.     {
  20.         instance= this;
  21.     }
  22.  
  23.     public void Follow(Vector3 movePosition)
  24.     {
  25.      
  26.         Vector2 moveVector = movePosition - this.transform.position;
  27.         moveVector = moveVector.Generalize();
  28.  
  29.         if (!charecter.IsMoving)
  30.         {
  31.             StartCoroutine(this.charecter.Move(moveVector, null, true));
  32.         }
  33.          
  34.         if(theZone.hasFallen == true)
  35.         {
  36.             StopCoroutine(this.charecter.Move(moveVector, null, true));
  37.         }
  38.  
  39.     }
  40.  
  41.     private void Start()
  42.     {
  43.         charecter = GetComponent<Charecter>();
  44.         this.transform.position = GameController.Instance.PlayerController.transform.position;
  45.     }
  46.  
  47.     private void Update()
  48.     {
  49.         if (CharecterSwap.istogether == false) return;
  50.         if (Vector3.Distance(transform.position, GameController.Instance.PlayerController.transform.position) > 3f)
  51.         {
  52.  
  53.             transform.position = GameController.Instance.PlayerController.transform.position;
  54.         }
  55.  
  56.         if (Vector3.Distance(transform.position, GameController.Instance.PlayerController.transform.position) > 15f)
  57.         {
  58.  
  59.             CharecterSwap.istogether= true;
  60.         }
  61.  
  62.  
  63.         charecter.HandleUpdate();
  64.  
  65.      
  66.     }
  67.  
  68.     public void OnSwitch(bool state)
  69.     {
  70.         player.playerActive = state;
  71.         GetComponent<Party>().enabled = state;
  72.         GetComponent<PlayerController>().enabled = state;
  73.         GetComponent<BuddyController>().enabled = !state;
  74.     }
  75.  
  76.  
  77.  
  78.     public void IsSeperated()
  79.     {
  80.         isActive= false;
  81.     }
  82.  
  83.     public void IsTogether()
  84.     {
  85.         isActive = true;
  86.     }
  87.  
  88.     public Charecter Charecter => charecter;
  89.  
  90.     Transform ISwitchable.thecurrentChar => this.transform;
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement