Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using MoreMountains.Feedbacks;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour {
- private Rigidbody2D rb;
- public CharacterController2D controller;
- public float runSpeed = 0f;
- [Header ("GlideStuff")]
- public KeyCode GlideKey; // key to glide
- [SerializeField] private float GlideGravity; // gravity change on glide key press
- float horizontalMove = 0f;
- float gravity;
- bool jump = false;
- bool crouch = false;
- [SerializeField] bool Land = false;
- bool isGrounded;
- bool dustStarted;
- [SerializeField] private int NumberOfJumps;
- private int MaxJumps;
- [Header ("dustSettings")]
- [SerializeField][Range (0, 1)] private float dustStartVelocity; //window at which the dust starts
- [SerializeField][Range (0, 1)] private float dustEndVelocity; // window at which the dust ends
- [Header ("MMFEEDBACKS")] // MMFEEDBACKS JUST MAKES EDITING STUFF AND MAKING ARTISTIC DECISIONS LATER ON FOR THE ARTISTS
- public MMFeedbacks crouchFeedback;
- public MMFeedbacks landFeedback;
- public MMFeedbacks jumpFeedback;
- public MMFeedbacks dustStartFeedback;
- public MMFeedbacks dustPloofFeedback;
- private void Start () {
- rb = GetComponent<Rigidbody2D> ();
- gravity = rb.gravityScale;
- }
- // Update is called once per frame
- void Update () {
- //set isgrounded to isgrounded
- isGrounded = controller.m_Grounded;
- //set move variable to button
- horizontalMove = Input.GetAxisRaw ("Horizontal") * runSpeed;
- SetJumpVariables ();
- DustCode ();
- MovementStates ();
- }
- void FixedUpdate () {
- //move our character
- controller.Move (horizontalMove * Time.fixedDeltaTime, crouch, jump);
- jump = false;
- }
- void DustCode () {
- //dust code__________________________________________________________________________________________________________________
- if (isGrounded) {
- if (!Land) {
- landFeedback.PlayFeedbacks ();
- Land = true;
- }
- if (Mathf.Abs (rb.velocity.x) >= dustStartVelocity) {
- if (!dustStarted) {
- dustStartFeedback.PlayFeedbacks ();
- dustStarted = true;
- }
- if (horizontalMove == 0) {
- bool stop = false;
- if (stop == false) {
- dustPloofFeedback.PlayFeedbacks ();
- stop = true;
- }
- }
- } else if (Mathf.Abs (rb.velocity.x) <= dustEndVelocity) {
- if (horizontalMove == 0) {
- if (dustStarted) {
- dustStartFeedback.StopFeedbacks ();
- dustStarted = false;
- }
- }
- } else { }
- } else if (!isGrounded) {
- Glide ();
- dustStartFeedback.StopFeedbacks ();
- dustStarted = false;
- }
- //end of dust code________________________________________________________________________________________
- }
- void Glide () {
- if (Input.GetKeyDown (GlideKey)) {
- rb.gravityScale = GlideGravity;
- } else if (Input.GetKeyUp (GlideKey)) {
- rb.gravityScale = gravity;
- }
- }
- void MovementStates () {
- if (Input.GetButtonDown ("Jump")) {
- if (NumberOfJumps != MaxJumps) {
- jumpFeedback.PlayFeedbacks ();
- jump = true;
- Land = false;
- } else { }
- }
- if (Input.GetButtonDown ("Crouch")) {
- crouch = true;
- crouchFeedback.PlayFeedbacks ();
- } else if (Input.GetButtonUp ("Crouch")) {
- crouch = false;
- crouchFeedback.PlayFeedbacksInReverse ();
- }
- }
- void SetJumpVariables () {
- NumberOfJumps = controller.NumberOfJumps;
- MaxJumps = controller.MaxJumps;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement