Created
June 3, 2019 19:18
-
-
Save pr00thmatic/6d0d192cfff50c77441a00da2b3d30bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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