TriggerRollerActive.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using DG.Tweening;
  6. [Serializable]
  7. public class TriggerRollerActive : MonoBehaviour
  8. {
  9. [SerializeField]
  10. public List<RollerController> Rollers;
  11. public Camera MainCamera;
  12. private void Start()
  13. {
  14. MainCamera = Camera.main;
  15. Rollers[_curIndex].gameObject.SetActive(true);
  16. }
  17. private void OnTriggerEnter(Collider other)
  18. {
  19. if (other.tag == "Player")
  20. {
  21. var rController = Rollers[_curIndex];
  22. other.GetComponent<RunnersController>().SetRollerAnim();
  23. StartCoroutine(SitTrolleyAnim(rController, other));
  24. //Invoke("ActiveController", 1);
  25. }
  26. }
  27. private IEnumerator SitTrolleyAnim(RollerController rController, Collider other)
  28. {
  29. yield return new WaitForSeconds(1);
  30. other.gameObject.SetActive(false);
  31. NotificationCenter.Post(NotificationType.RollerActive, other.gameObject);
  32. if (other.gameObject == Core.Instance._player.name.Contains(other.name))
  33. {
  34. MainCamera.transform.SetParent(Rollers[_curIndex].TrCamera);
  35. MainCamera.GetComponent<CompleteCameraController>().enabled = false;
  36. MainCamera.transform.DOLookAt(Rollers[_curIndex].Roller.transform.position, 0.3f);
  37. Rollers[_curIndex].Initializaion(other.gameObject);
  38. ActiveController();
  39. }
  40. else
  41. {
  42. Rollers[_curIndex].Initializaion(other.gameObject);
  43. ActiveController();
  44. }
  45. }
  46. private void OnRollerActive(Notification note)
  47. {
  48. }
  49. public void ResetRolley()
  50. {
  51. _curIndex = 0;
  52. for (var i= 0; i< Rollers.Count;i++)
  53. {
  54. Rollers[i].Roller.gameObject.SetActive(true);
  55. }
  56. }
  57. public int _curIndex = 0;
  58. public void ActiveController()
  59. {
  60. _curIndex++;
  61. if (_curIndex < Rollers.Count)
  62. {
  63. Rollers[_curIndex].gameObject.SetActive(true);
  64. }
  65. }
  66. }