I assume the lines you don't understand are those you put comments on, so I will explain them in order.
- A method returning an
IEnumerator
is one which can use theyield 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. Theyield 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. - The
a ? b : c
construct in C# is the Ternary Condition Operator. It returns a single value. Ifa
istrue
, it returnsb
, otherwise it returnsc
. In this casea
isTarget.y == Top.y
. So in plain English, this line means "IfTarget.y
is equalTop.y
,Direction
is up, otherwise Direction is down". - And so,
Vector3 newTarget = Target.y ==Top.y ? Bottom : Top;
means "IfTarget.y
is equalTop.y
, then head towardsBottom
, otherwise head towardsTop
"