Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

  IEnumerator init() {
   Stopwatch timer = new Stopwatch();
   timer.Start();

   //wait for nodes
   while (!grid.IsReady) yield return null;
   //wait for pieces
   while (!grid.ArePiecesSpawned) yield return null; //wait till pieces are spawned
   while (!p1.IsReady) yield return null; //wait till all pieces are scaled in
   while (!p2.IsReady) yield return null;
   print("Time elapsed: " + timer.ElapsedMilliseconds / 1000.0 + "s");
   timer.Stop();

   //IMPORTANT
   p1.ComputePieces();
   p2.ComputePieces();
   SwitchPlayer(); //if null current player = p1

   //all objects are now ready
   ready = true;
  }