Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / PlayerController.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Cinemachine;
  6. public class PlayerController : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private CinemachineFreeLook cinemachineFreeLook;
  10. [HideInInspector]
  11. public Mana manaScript;
  12. [HideInInspector]
  13. public Health healthScript;
  14. [HideInInspector]
  15. public Rigidbody rb;
  16. [HideInInspector]
  17. public int directionPushAndPull = 1;
  18. [HideInInspector]
  19. public bool pushAndPull = false;
  20. [HideInInspector]
  21. public BoxScript currentTarget = null;
  22. private float pushAndPullCoolDown = 0.5f;
  23. public bool intention = true;
  24. private Text intentText;
  25. public List<AbilitieAndCode> abilities;
  26. // Focus
  27. [HideInInspector]
  28. public float timerFocusTotal;
  29. private float timerFocus;
  30. [HideInInspector]
  31. public bool focusTrigger = false;
  32. private bool endFocus = false;
  33. [HideInInspector]
  34. public float timeMultiplier;
  35. //Dash
  36. [HideInInspector]
  37. public float immortalityTimer;
  38. [HideInInspector]
  39. public bool dashing = false;
  40. //Inputs
  41. [HideInInspector]
  42. public float xInput;
  43. [HideInInspector]
  44. public float zInput;
  45. private Rigidbody currentTargetrb;
  46. [SerializeField]
  47. //private Animator animator;
  48. private float animationTimer;
  49. //WorldLimiter
  50. [HideInInspector]
  51. public Vector3 transpassedCoordinate = Vector3.zero;
  52. PostProcessingController postProcessingController;
  53. void Start()
  54. {
  55. manaScript = GetComponent<Mana>();
  56. healthScript = GetComponent<Health>();
  57. rb = GetComponent<Rigidbody>();
  58. timeMultiplier = 1;
  59. intentText = GameObject.FindGameObjectWithTag("PushPullText").GetComponent<Text>();
  60. postProcessingController = Camera.main.GetComponent<PostProcessingController>();
  61. if (StoredTeleport.teleported)
  62. {
  63. healthScript.deathPos = StoredTeleport.position;
  64. StoredTeleport.teleported = false;
  65. transform.position = StoredTeleport.position;
  66. }
  67. }
  68. void Update()
  69. {
  70. zInput = Input.GetAxis("Vertical");
  71. xInput = Input.GetAxis("Horizontal");
  72. if (Input.GetKeyDown(KeyCode.Q)) intention = !intention;
  73. if (intention)
  74. {
  75. if (Input.GetKeyDown(abilities[0].code))
  76. {
  77. //Attack
  78. //animator.SetTrigger("Attack");
  79. }
  80. if (Input.GetKeyDown(abilities[5].code))
  81. {
  82. //Parry
  83. abilities[5].ability.Effects(this);
  84. }
  85. intentText.text = "Combat";
  86. }
  87. else
  88. {
  89. intentText.text = "Push And Pull";
  90. if (Input.GetKey(abilities[3].code) || Input.GetKey(abilities[4].code))
  91. {
  92. //PushAndPull
  93. if (Input.GetKeyDown(abilities[3].code))
  94. {
  95. directionPushAndPull = 1;
  96. }
  97. if (Input.GetKeyDown(abilities[4].code))
  98. {
  99. directionPushAndPull = -1;
  100. }
  101. if (!pushAndPull)
  102. {
  103. abilities[3].ability.Effects(this);
  104. pushAndPull = true;
  105. if (currentTarget != null)
  106. currentTargetrb = currentTarget.GetComponent<Rigidbody>();
  107. }
  108. }
  109. else EndPushAndPull();
  110. }
  111. if((Input.GetKeyDown(abilities[1].code) && !focusTrigger) || endFocus)
  112. {
  113. //Focus
  114. abilities[1].ability.Effects(this);
  115. timerFocus = timerFocusTotal;
  116. endFocus = false;
  117. }
  118. if (Input.GetKeyDown(abilities[2].code))
  119. {
  120. //Dash
  121. // animator.SetBool("Dash", true);
  122. //animator.SetTrigger("DashTrigger");
  123. abilities[2].ability.Effects(this);
  124. }
  125. Timer();
  126. cinemachineFreeLook.m_XAxis.m_MaxSpeed = 300 * timeMultiplier;
  127. cinemachineFreeLook.m_YAxis.m_MaxSpeed = 2 * timeMultiplier;
  128. }
  129. public void Attack()
  130. {
  131. abilities[0].ability.Effects(this);
  132. }
  133. private void Timer()
  134. {
  135. //Focus Timer
  136. if (timerFocus > 0) timerFocus -= Time.deltaTime * timeMultiplier;
  137. else if (focusTrigger) { endFocus = true; focusTrigger = false; }
  138. //Dash Immortality Timer
  139. if (immortalityTimer > 0) immortalityTimer -= Time.deltaTime * timeMultiplier;
  140. else { healthScript.immortality = false; dashing = false; }
  141. if (pushAndPullCoolDown > 0) pushAndPullCoolDown -= Time.deltaTime * timeMultiplier;
  142. }
  143. private void FixedUpdate()
  144. {
  145. if (pushAndPull) abilities[3].ability.Effects(this);
  146. if (currentTarget == null) pushAndPull = false;
  147. }
  148. public void EndPushAndPull()
  149. {
  150. if (currentTarget != null)
  151. {
  152. currentTarget.Manipulation(false);
  153. if(currentTarget.CompareTag("Box"))
  154. currentTargetrb.velocity = Vector3.zero;
  155. currentTarget = null;
  156. }
  157. }
  158. }