protected override void SetNextSection(RailSection next) { if(rail == null) { rail = next; // initial rail } else { railQueue.Enqueue(next); } PropagateNextSection(next); }
public void Move() { if(railPos == -1) { /// we're just starting, figure out our initial railPos from /// how far we are from the rail railPos = (transform.position - rail.transform.position).magnitude; } railPos += Time.deltaTime * speed; Vector3 newPos = rail.GetPosition(railPos); if(newPos != transform.position) { transform.rotation = Quaternion.LookRotation(newPos - transform.position); } transform.position = newPos; float remainder = rail.GetRemainder(railPos); if(remainder > 0) { rail = GetNextSection(); railPos = remainder; if(rail == null) { Debug.LogError("End of the line!"); Debug.Break(); } } }
protected abstract void SetNextSection(RailSection next);
protected void PropagateNextSection(RailSection next) { if(nextCar != null) { nextCar.SetNextSection(next); } }
protected override void SetNextSection(RailSection next) { throw new System.NotImplementedException("Driver shouldn't get its rail set"); }