Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created June 3, 2019 19:18
Show Gist options
  • Save pr00thmatic/6d0d192cfff50c77441a00da2b3d30bd to your computer and use it in GitHub Desktop.
Save pr00thmatic/6d0d192cfff50c77441a00da2b3d30bd to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Corrutinas : MonoBehaviour {
public bool control = true;
public Coroutine move = null;
void Start () {
StartCoroutine(Rotar());
}
void Update () {
if (control && Input.GetKeyDown(KeyCode.Space)) {
if (move != null) {
StopCoroutine(move);
}
move = StartCoroutine(Mover());
}
if (Input.GetKeyDown(KeyCode.Q)) {
Time.timeScale += 0.2f;
}
if (Input.GetKeyDown(KeyCode.A)) {
Time.timeScale = Mathf.Max(0, Time.timeScale - 0.2f);
}
}
public void Unpause () {
Time.timeScale = 1;
}
IEnumerator Mover () {
float initialTime = Time.time;
while (Time.time < initialTime + 3) {
transform.Translate(0, 0, 5 * Time.deltaTime);
yield return null;
}
move = null;
}
IEnumerator Rotar () {
// while (Time.time < Random.Range(3, 8f)) {
while (true) {
transform.Rotate(0, 180 * Time.deltaTime, 0);
yield return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment