Skip to content

Instantly share code, notes, and snippets.

@ColeMundus
Created March 8, 2017 23:06
Show Gist options
  • Save ColeMundus/74d7d51b69fb5c050eb56fabac817d79 to your computer and use it in GitHub Desktop.
Save ColeMundus/74d7d51b69fb5c050eb56fabac817d79 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MCSAnimController : MonoBehaviour {
public Slider sprintSlider;
public Text scoreText;
public float runningCooldown;
public int turnSpeed;
private Animator anim;
private float walking;
private float turning;
private bool isRunning;
private int hitCount;
void Start () {
anim = GetComponent<Animator> ();
sprintSlider.value = 10.0f;
runningCooldown = 10.0f;
walking = 0.0f;
turning = 0.0f;
hitCount = 0;
isRunning = false;
}
void Update () {
walking = Input.GetAxis ("Vertical");
anim.SetFloat ("walking", walking);
turning = Input.GetAxis ("Horizontal");
transform.Rotate (new Vector3 (0.0f, turnSpeed * turning * Time.deltaTime));
if (Input.GetKey (KeyCode.LeftShift)) {
if (runningCooldown > 3.0f) {
anim.SetFloat ("running", 1.0f);
isRunning = true;
} else if (isRunning && runningCooldown < 3.0f && runningCooldown > 0.0f){
anim.SetFloat ("running", 1.0f);
isRunning = true;
} else {
anim.SetFloat ("running", 0.0f);
isRunning = false;
}
} else {
anim.SetFloat ("running", 0.0f);
isRunning = false;
}
if (isRunning) {
if (runningCooldown <= 0.0f) {
anim.SetFloat ("running", 0.0f);
} else {
runningCooldown -= 1.0f * Time.deltaTime;
sprintSlider.value = runningCooldown;
}
} else {
if (runningCooldown < 10.0f) {
runningCooldown += 0.3f * Time.deltaTime;
sprintSlider.value = runningCooldown;
}
}
}
void OnTriggerEnter(Collider other){
other.gameObject.GetComponent<Renderer>().enabled = false;
hitCount++;
scoreText.text = "Energy Cans: " + hitCount.ToString();
if (runningCooldown < 10.0f) {
if (runningCooldown < 5.0f) {
runningCooldown += 5.0f;
} else {
runningCooldown = 10.0f;
}
}
StartCoroutine(ObjRespawn (other));
}
IEnumerator ObjRespawn(Collider other){
yield return new WaitForSeconds(30);
other.gameObject.GetComponent<Renderer>().enabled = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment