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
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitignore":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}
\ 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() {
ToggleScripts(false);
previousGravity = body.gravityScale;
body.velocity.Set(body.velocity.x, speed);
body.gravityScale = 0;
_isSliding = true;
isEnding = false;
isJumping = false;
StartCoroutine(CheckForEnd());
}
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);
EndSliding();
}
private void EndSliding() {
body.gravityScale = previousGravity;
_isSliding = false;
isJumping = false;
ToggleScripts(true);
}
}
fileFormatVersion: 2
guid: 604ce289803c4154f97ae0b77cd158b7
timeCreated: 1486689234
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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