Skip to content

Instantly share code, notes, and snippets.

@vjgrayman
Last active July 18, 2019 19:50
Show Gist options
  • Save vjgrayman/a897efb1f2a919b5eedd948c356ecc3f to your computer and use it in GitHub Desktop.
Save vjgrayman/a897efb1f2a919b5eedd948c356ecc3f to your computer and use it in GitHub Desktop.
[CSharpSurvival_2] #CSharp
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 10; i++)
{
/*
// Print Even Number
if (i % 2 == 0)
{
Debug.Log(i);
}
*/
// Print Odd Number
if (i % 2 == 1)
{
Debug.Log(i);
}
}
Debug.Log("Loop has Finished");
}
// Update is called once per frame
void Update()
{
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 100; i++)
{
Debug.Log(i);
if (i == 50)
{
break;
}
}
Debug.Log("Loop has Finished");
}
// Update is called once per frame
void Update()
{
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public int apples;
// Start is called before the first frame update
void Start()
{
StartCoroutine(AddApplesRoutine());
}
// Update is called once per frame
void Update()
{
}
IEnumerator AddApplesRoutine()
{
for (int i=0; i<100; i++)
{
apples++;
yield return new WaitForSeconds(0.5f);
}
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public int apples;
// Start is called before the first frame update
void Start()
{
while (apples < 50)
{
Debug.Log("My name is gray");
apples++;
//<-- 제한조건이 정확하지 않을 경우 infinite loop이 될 수 있음
}
}
// Update is called once per frame
void Update()
{
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
for (int i = 0; i <= 10; i++)
{
Debug.Log(i);
}
for (int i = 11; i <= 20; i++)
{
if (i % 2 == 0)
{
Debug.Log(i);
}
}
for (int i = 21; i <= 30; i++)
{
if (i % 2 == 1)
{
Debug.Log(i);
}
}
}
// Update is called once per frame
void Update()
{
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public int speed;
public int maxSpeed;
// Start is called before the first frame update
void Start()
{
maxSpeed = Random.Range(60, 120);
StartCoroutine(SpeedRoutine());
}
// Update is called once per frame
void Update()
{
}
IEnumerator SpeedRoutine()
{
while (true)
{
speed += 5;
yield return new WaitForSeconds(0.5f);
if (speed > maxSpeed)
{
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment