- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using Cinemachine;
- public class PlayerController : MonoBehaviour
- {
- [SerializeField]
- private CinemachineFreeLook cinemachineFreeLook;
- [HideInInspector]
- public Mana manaScript;
- [HideInInspector]
- public Health healthScript;
- [HideInInspector]
- public Rigidbody rb;
- [HideInInspector]
- public int directionPushAndPull = 1;
- [HideInInspector]
- public bool pushAndPull = false;
- [HideInInspector]
- public BoxScript currentTarget = null;
- private float pushAndPullCoolDown = 0.5f;
- public bool intention = true;
- private Text intentText;
- public List<AbilitieAndCode> abilities;
-
-
- // Focus
- [HideInInspector]
- public float timerFocusTotal;
- private float timerFocus;
- [HideInInspector]
- public bool focusTrigger = false;
- private bool endFocus = false;
- [HideInInspector]
- public float timeMultiplier;
- //Dash
- [HideInInspector]
- public float immortalityTimer;
- [HideInInspector]
- public bool dashing = false;
- //Inputs
- [HideInInspector]
- public float xInput;
- [HideInInspector]
- public float zInput;
- private Rigidbody currentTargetrb;
- [SerializeField]
- //private Animator animator;
- private float animationTimer;
- //WorldLimiter
- [HideInInspector]
- public Vector3 transpassedCoordinate = Vector3.zero;
- PostProcessingController postProcessingController;
- void Start()
- {
- manaScript = GetComponent<Mana>();
- healthScript = GetComponent<Health>();
- rb = GetComponent<Rigidbody>();
- timeMultiplier = 1;
- intentText = GameObject.FindGameObjectWithTag("PushPullText").GetComponent<Text>();
- postProcessingController = Camera.main.GetComponent<PostProcessingController>();
- if (StoredTeleport.teleported)
- {
- healthScript.deathPos = StoredTeleport.position;
- StoredTeleport.teleported = false;
- transform.position = StoredTeleport.position;
- }
- }
- void Update()
- {
- zInput = Input.GetAxis("Vertical");
- xInput = Input.GetAxis("Horizontal");
- if (Input.GetKeyDown(KeyCode.Q)) intention = !intention;
- if (intention)
- {
- if (Input.GetKeyDown(abilities[0].code))
- {
- //Attack
- //animator.SetTrigger("Attack");
- }
- if (Input.GetKeyDown(abilities[5].code))
- {
- //Parry
- abilities[5].ability.Effects(this);
- }
- intentText.text = "Combat";
- }
- else
- {
- intentText.text = "Push And Pull";
- if (Input.GetKey(abilities[3].code) || Input.GetKey(abilities[4].code))
- {
- //PushAndPull
-
- if (Input.GetKeyDown(abilities[3].code))
- {
- directionPushAndPull = 1;
- }
- if (Input.GetKeyDown(abilities[4].code))
- {
- directionPushAndPull = -1;
- }
- if (!pushAndPull)
- {
- abilities[3].ability.Effects(this);
- pushAndPull = true;
- if (currentTarget != null)
- currentTargetrb = currentTarget.GetComponent<Rigidbody>();
- }
- }
- else EndPushAndPull();
- }
- if((Input.GetKeyDown(abilities[1].code) && !focusTrigger) || endFocus)
- {
- //Focus
- abilities[1].ability.Effects(this);
- timerFocus = timerFocusTotal;
- endFocus = false;
- }
- if (Input.GetKeyDown(abilities[2].code))
- {
- //Dash
- // animator.SetBool("Dash", true);
- //animator.SetTrigger("DashTrigger");
- abilities[2].ability.Effects(this);
- }
-
- Timer();
- cinemachineFreeLook.m_XAxis.m_MaxSpeed = 300 * timeMultiplier;
- cinemachineFreeLook.m_YAxis.m_MaxSpeed = 2 * timeMultiplier;
-
- }
- public void Attack()
- {
- abilities[0].ability.Effects(this);
- }
- private void Timer()
- {
- //Focus Timer
- if (timerFocus > 0) timerFocus -= Time.deltaTime * timeMultiplier;
- else if (focusTrigger) { endFocus = true; focusTrigger = false; }
- //Dash Immortality Timer
- if (immortalityTimer > 0) immortalityTimer -= Time.deltaTime * timeMultiplier;
- else { healthScript.immortality = false; dashing = false; }
- if (pushAndPullCoolDown > 0) pushAndPullCoolDown -= Time.deltaTime * timeMultiplier;
-
- }
- private void FixedUpdate()
- {
-
- if (pushAndPull) abilities[3].ability.Effects(this);
- if (currentTarget == null) pushAndPull = false;
- }
- public void EndPushAndPull()
- {
- if (currentTarget != null)
- {
- currentTarget.Manipulation(false);
- if(currentTarget.CompareTag("Box"))
- currentTargetrb.velocity = Vector3.zero;
- currentTarget = null;
-
- }
- }
-
- }