Commit 6e910a70 authored by Joshua DeRossett's avatar Joshua DeRossett

Adding Wall Sliding Script

parent 8d13b79d
\ No newline at end of file
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallSliding : AbstractBehavior {
[SerializeField] private float speed;
[SerializeField] private float delay;
[SerializeField] private float wallJumpForce;
[SerializeField] private int leftButtonID;
[SerializeField] private int rightButtonID;
[SerializeField] private int jumpButtonID;
private float previousGravity;
private bool _isSliding;
private bool isEnding;
private bool isJumping;
public void Activate() {
previousGravity = body.gravityScale;
body.velocity.Set(body.velocity.x, speed);
body.gravityScale = 0;
_isSliding = true;
isEnding = false;
isJumping = false;
private IEnumerator CheckForEnd() {
while (_isSliding) {
if (ButtonCheck(leftButtonID) || ButtonCheck(rightButtonID)) {
if (!isEnding) StartCoroutine(EndWithDelay());
if (ButtonCheck(jumpButtonID)) {
if (!isJumping) JumpOffWall();
if (!isEnding) EndSliding();
yield return new WaitForFixedUpdate();
private bool ButtonCheck(int button) {
return inputState.GetButtonValue(inputButtons[button]);
private void JumpOffWall() {
isJumping = true;
body.AddForce(new Vector2((int)inputState.direction, 0) * wallJumpForce);
private IEnumerator EndWithDelay() {
isEnding = true;
yield return new WaitForSeconds(delay);
private void EndSliding() {
body.gravityScale = previousGravity;
_isSliding = false;
isJumping = false;
fileFormatVersion: 2
guid: 604ce289803c4154f97ae0b77cd158b7
timeCreated: 1486689234
licenseType: Pro
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
m_EditorVersion: 5.3.5f1
m_StandardAssetsVersion: 0
m_EditorVersion: 5.5.0f3
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment