using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.Events; public class PlayerController : MonoBehaviour { [SerializeField] private GameObject player; private IMovable movementPlayer; private StatusEffects sE; private float speed; //Variables to control the movement that needs to be on the fixed update, but influenced by inputs private bool moving; private float horizontalAxis; public bool aswitch { get; private set; } private bool rogueAbility; //public List<ClassBaseType> classes; private ClassSelection cS; private WeaponScript mg; private int currentClassIndex; private ClassBaseType currentClass; void Start() { movementPlayer = GetComponent<IMovable>(); sE = GetComponent<StatusEffects>(); mg = GetComponent<WeaponScript>(); cS= GetComponent<ClassSelection>(); Debug.Log(cS); } void Update() { //All the inputs will come from the update, if changed please use the unity inputs, since we want to do the input system on the menu. if (movementPlayer != null && sE != null) { horizontalAxis = Input.GetAxis("Horizontal"); float t = Input.GetAxis("Mouse ScrollWheel"); if (t != 0) { mg.ChangeWeapon(t); } if (Input.anyKey && !movementPlayer.GetBlockMovement()) { if (Input.GetButtonDown("Jump")) { if (movementPlayer.OnGround()) { //drag is changed to 0 if in midair in order to have more controll. movementPlayer.ChangeDrag(0); movementPlayer.ChangeVelocity(new Vector3(movementPlayer.GetVelocity().x, sE.jumpForce, movementPlayer.GetVelocity().z)); } } if (horizontalAxis != 0 && Input.GetButton("Horizontal")) { moving = true; if (movementPlayer.OnGround()) { //if the player is asking to move the pawn. movementPlayer.ChangeDrag(0); } } else moving = false; if (Input.GetButton("Fire1")) { Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position); Vector3 mouseDir = Vector3.Normalize(Input.mousePosition - screenPos); mg.Shoot(mouseDir); } } } if (Input.GetKeyDown(KeyCode.Q)) { cS.SwitchClasses(); } cS.CoolDowns(); cS.UseAbility(); } public void TemporaryUISwitch() { aswitch = !aswitch; } private void FixedUpdate() { if (movementPlayer != null) { if (!movementPlayer.OnGround()) { //Check if the player is in midair, this is more if the midair is originated because the player fell. movementPlayer.ChangeDrag(0); speed = sE.speedAir; //Increases the gravity just for this pawn. if(movementPlayer.GetGravity()) movementPlayer.AddForce(Vector3.down * sE.increasedGravity); } else speed = sE.speedGround; if (Mathf.Abs(horizontalAxis) < 1) { //if the player is trying to stop moving or changing directions if (movementPlayer.OnGround()) movementPlayer.ChangeDrag(sE.dragStop); } if (moving && !movementPlayer.GetBlockMovement()) { movementPlayer.Move(Vector3.right, speed, speed * horizontalAxis); } } } }