TriggerRollerDeactive.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. public class TriggerRollerDeactive : MonoBehaviour
  6. {
  7. public List<RollerController> ListRollers;
  8. private int _curIndex = 0;
  9. public List<Transform> SpawnPointPlayer;
  10. private LevelTargets _levelTargets;
  11. private LevelTargets GetTargets()
  12. {
  13. return LevelManager.Instance.CurLevel.LevelTargets;
  14. }
  15. private void Start()
  16. {
  17. }
  18. public void ResetRolley()
  19. {
  20. _curIndex = 0;
  21. //for (var i = 0; i < ListRollers.Count; i++)
  22. //{
  23. // ListRollers[i].Roller.gameObject.SetActive(true);
  24. //}
  25. }
  26. private void OnTriggerEnter(Collider other)
  27. {
  28. if (other.tag == "Player")
  29. {
  30. var rController = ListRollers[_curIndex];
  31. other.gameObject.SetActive(false);
  32. rController.StopRoller();
  33. var r = UnityEngine.Random.Range(0, SpawnPointPlayer.Count - 1);
  34. Debug.Log(r);
  35. var agent = rController.Player.GetComponent<RunnersController>().Agent;
  36. rController.Player.transform.SetParent(SpawnPointPlayer[r]);
  37. rController.Player.transform.localPosition = Vector3.zero;
  38. rController.Player.transform.localScale = Vector3.one;
  39. _levelTargets = LevelManager.Instance.CurLevel.LevelTargets;
  40. rController.Player.GetComponent<RunnersController>().SetTarget(_levelTargets.ListLevelTargets[1]);
  41. DeactiveController();
  42. switch(Core.Instance.CurGender)
  43. {
  44. case Core.Gender.Male:
  45. rController.Player.transform.SetParent(Core.Instance.ParentMale);
  46. break;
  47. case Core.Gender.Female:
  48. rController.Player.transform.SetParent(Core.Instance.ParentFemale);
  49. break;
  50. }
  51. rController.Player.SetActive(true);
  52. //rController.Player.GetComponent<RunnersController>().Start();
  53. //Debug.Log(_levelTargets.CurTarget);
  54. //_levelTargets.CurTarget++;
  55. if (rController.Player.GetComponent<RunnersController>().IsPlayer)
  56. {
  57. rController.Player.SetActive(true);
  58. UIManager.Instance.Camera.transform.SetParent(null);
  59. UIManager.Instance.Camera.GetComponent<CompleteCameraController>().enabled = true;
  60. }
  61. rController.Player.GetComponent<RunnersController>().Move();
  62. NotificationCenter.Post(NotificationType.RollerDeactive, other.gameObject);
  63. }
  64. }
  65. public void DeactiveController()
  66. {
  67. _curIndex++;
  68. if(_curIndex< ListRollers.Count)
  69. {
  70. ListRollers[_curIndex].gameObject.SetActive(true);
  71. }
  72. }
  73. }