Commit e77d1274 authored by Luke A Smith's avatar Luke A Smith
Browse files

Merge branch 'WallSliding' into 'master'

Adding Wall Sliding Script

See merge request !10
parents 338c1638 8577a09b
\ 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}
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