Created
April 1, 2020 10:15
-
-
Save openroomxyz/523871ea47ed52c25b5794d76c95c648 to your computer and use it in GitHub Desktop.
Unity C# : How to use Generators example?
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Generator : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
var allNumbers = CosmosCount(); | |
foreach (float num in allNumbers) | |
{ | |
Debug.Log("LOL : " + num); | |
} | |
} | |
public static IEnumerable<float> CosmosCount() | |
{ | |
for(int i = 0; i < int.MaxValue; i++) | |
{ | |
if(i < 1000) | |
{ | |
yield return i; | |
} | |
else | |
{ | |
yield break; | |
} | |
} | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment