Advertisement
GoodNoodle

BuddyController

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