Commit 95005fdc authored by Andrew R Van Buren's avatar Andrew R Van Buren

Merge branch 'dashmeter' into 'master'

Dashmeter

See merge request !8
parents 49e9c0b7 3fcdef22
fileFormatVersion: 2
guid: a58ae0e00797d794297ccb4228d903bf
folderAsset: yes
timeCreated: 1487292663
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: fa60ffd6264804b43bc03430e8dd86b1
timeCreated: 1487292666
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Sets dash velocity and smoothly decelerates to a minimum velocity
public class Dash : AbstractBehavior {
private float lastDash;
public float coolDown = 1f;
public float dashforce = 5;
public float holdTime = 0.4f;
public float minVelocity = 0.5f;
// Should be called every frame
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Sets dash velocity and smoothly decelerates to a minimum velocity
public class Dash : AbstractBehavior {
private float lastDash;
public float coolDown = 1f;
public float dashforce = 5;
public float holdTime = 0.4f;
public float minVelocity = 0.5f;
private bool _isDashing = false;
private Transform dashMeter;
// Call to check if currently dashing
public bool isDashing
{
get { return _isDashing; }
private set
{
_isDashing = value;
}
}
void Start() {
dashMeter = GameObject.FindGameObjectWithTag("DashMeter").transform;
}
// Should be called every frame
public void DashCheck() {
// Button pressed, not in cooldown, and not on wall
if (inputState.GetButtonValue(inputButtons[0]) && Time.time > lastDash && !collisionState.onWall) {
StartCoroutine(DoDash());
}
}
// Dash
UpdateUI();
}
void UpdateUI() {
float progress = 1 - ((lastDash - Time.time)/coolDown);
dashMeter.localScale = new Vector2(Mathf.Clamp01(progress), dashMeter.localScale.y);
}
// Dash
IEnumerator DoDash() {
// Cooldown
lastDash = Time.time + coolDown;
// Is dashing
isDashing = true;
// Set initial velocity
body.velocity = transform.right * dashforce;
// Disable gravity
......@@ -39,7 +63,6 @@ public class Dash : AbstractBehavior {
if(body.velocity.magnitude < minVelocity || collisionState.onWall) {
// Velocity is low enough or collision with wall
Debug.Log("Stopped");
break;
}
......@@ -51,5 +74,11 @@ public class Dash : AbstractBehavior {
// Restore gravity
body.gravityScale = initialGrav;
}
}
// Is not dashing
isDashing = false;
}
public void DashIgnoringCooldown() {
StartCoroutine(DoDash());
}
}
fileFormatVersion: 2
guid: 763513e1173772545a16c3cb1a4d40d5
timeCreated: 1486688527
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
......
fileFormatVersion: 2
guid: 79af5acd6c178454090143472b307c76
timeCreated: 1486692331
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
......
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