Skip to main content
2 of 7
added 164 characters in body
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 return instruction in order to get executed in chunks. 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 that point at a later time.
  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"
Philipp
  • 121.5k
  • 28
  • 261
  • 342