Skip to main content
Commonmark migration
Source Link
  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

    A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

    Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command queues and behavior trees, but that's a personal preference).

  2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down".

  3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command queues and behavior trees, but that's a personal preference). 2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down". 3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command queues and behavior trees, but that's a personal preference). 2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down". 3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

    Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command queues and behavior trees, but that's a personal preference).

  2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down".

  3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

edited body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

I assume the lines you don't understand are those you put comments on, so I will explain them in order.

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command stacksqueues and behavior trees, but that's a personal preference). 2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down". 3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

I assume the lines you don't understand are those you put comments on, so I will explain them in order.

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command stacks and behavior trees, but that's a personal preference). 2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down". 3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

I assume the lines you don't understand are those you put comments on, so I will explain them in order.

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command queues and behavior trees, but that's a personal preference). 2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down". 3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

added 128 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

I assume the lines you don't understand are those you put comments on, so I will explain them in order.

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return). Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without adding more state to your game objects or opening up the box of pandora which is actual multi-threading.
  2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down".
  3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command stacks and behavior trees, but that's a personal preference). 2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down". 3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

I assume the lines you don't understand are those you put comments on, so I will explain them in order.

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return). Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without adding more state to your game objects or opening up the box of pandora which is actual multi-threading.
  2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down".
  3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

I assume the lines you don't understand are those you put comments on, so I will explain them in order.

  1. A method returning an IEnumerator is one which can use the yield instruction to return values to the caller. Whenever the program flow reaches a yield, the program flow goes back to the caller. The caller can then process that value and then resume the execution of the enumerator-method after the yield instruction (or not). When you encounter such a method in a Unity project, then it is usually used for a Coroutine. The yield return's in a coroutine are the points where the program flow returns to the engine which will then resume the coroutine at a later time (how much later depends on what value you yield return).

Unity Coroutines can be an elegant way to express processes which are supposed to take multiple frames to complete without having to add complicated state-determination logic to your Update methods or opening up the box of pandora which is actual multi-threading (I personally prefer state machines, command stacks and behavior trees, but that's a personal preference). 2. The a ? b : c construct in C# is the Ternary Condition Operator. It returns a single value. If a is true, it returns b, otherwise it returns c. In this case a is Target.y == Top.y. So in plain English, this line means "If Target.y is equal Top.y, Direction is up, otherwise Direction is down". 3. And so, Vector3 newTarget = Target.y ==Top.y ? Bottom : Top; means "If Target.y is equal Top.y, then head towards Bottom, otherwise head towards Top"

added 226 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading
added 164 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading
added 164 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading