title: Unity c# mario game
body: <p>I am following this youtube series that creates a Unity 3D Mario game.
  ( <a href="https://www.youtube.com/watch?v=vjL3S5dKLN4&amp;index=6&amp;list=PLZ1b66Z1KFKgm4QrzZ11jfaeHVaWHSHW7" rel="nofollow noreferrer">https://www.youtube.com/watch?v=vjL3S5dKLN4&amp;index=6&amp;list=PLZ1b66Z1KFKgm4QrzZ11jfaeHVaWHSHW7</a> )</p>
  
  <p>So I am trying to recreate the "going down the pipe" script like on the Mario game. I create an <strong>Animator</strong> and I am trying to trigger the animation using a C# script on key down press.</p>
  
  <p><strong>1. The problem:</strong>
  This guys writes his scripts in Javascript and apparently my Unity version does no longer support js so I need to write it in C# ( and I prefer writing it in C#).</p>
  
  <p>Basically I need to convert this js to c#:</p>
  
  <pre><code>var PipeEntry : GameObject;
  var StoodOn : int;
  
  
  function OnTriggerEnter (col : Collider) {
      StoodOn = 1;
  }
  
  function OnTriggerExit (col : Collider) {
      StoodOn = 0;
  }
  
  
  function Update () {
      if (Input.GetButtonDown("GoDown")) {
          if (StoodOn == 1) {
              //GameObject.Find("FPSController").GetComponent("FirstPersonController").enabled=false;
              transform.position = Vector3(0, -1000, 0);
              WaitingForPipe();
          }
      }
  }
  
  function WaitingForPipe () {
      PipeEntry.GetComponent("Animator").enabled=true;
      yield WaitForSeconds(2);
      PipeEntry.GetComponent("Animator").enabled=false;
      //GameObject.Find("FPSController").GetComponent("FirstPersonController").enabled=true;
  }
  </code></pre>
  
  <p><strong>2. MY CODE</strong></p>
  
  <p>My script currently looks like this:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  // 
  using UnityStandardAssets.Characters.FirstPerson;
  
  public class PipeEntry : MonoBehaviour
  {
      public GameObject pipe_entry;
      public int StoodOn;
      public int has_run = 0;
      public int waiting_pipe = 0;
      public int waiting_pipe_animation = 0;
  
      IEnumerator OnTriggerEnter(Collider col)
      {
          StoodOn = 1;
          yield return StoodOn;
      }
  
      IEnumerator OnTriggerExit(Collider col)
      {
          StoodOn = 0;
          yield return StoodOn;
      }
  
      IEnumerator WaitPipeAnimation()
      {
          waiting_pipe_animation = 1;
          yield return new WaitForSeconds(2);
  
      }
  
      // Update is called once per frame
      void Update()
      {
          if (Input.GetButtonDown("PipeDown"))
          {
              if (StoodOn == 1)
              {
                  // Freeze player
                  //GameObject.Find("Player").GetComponent&lt;FirstPersonController&gt;().enabled = false;
                  transform.position = new Vector3(0, -1000, 0);
                  WaitingForPipe();
                  has_run = 1;
              }
          }
      }
  
      public void WaitingForPipe()
      {
          pipe_entry.GetComponent&lt;Animator&gt;().enabled = true;
          WaitPipeAnimation();
          pipe_entry.GetComponent&lt;Animator&gt;().enabled = false;
          waiting_pipe = 1;
          //GameObject.Find("Player").GetComponent&lt;FirstPersonController&gt;().enabled = true;
      }
  
      // Start is called before the first frame update
      void Start()
      {
  
      }
  }
  </code></pre>
  
  <p><strong>3. Facts</strong></p>
  
  <ul>
  <li><p>The animation works good if triggered directly from Unity, so the script does not work.</p></li>
  <li><p>I set some debug variables that are set to value 1 too where script breaks and <strong>waiting_pipe_animation</strong> is the only one that doesn't reach.</p></li>
  </ul>
  
  <p><strong>4. UPDATE</strong>
  - So basically the main issue is with this function:</p>
  
  <pre><code>yield return new WaitForSeconds(2);
  </code></pre>
  
  <p>If I place it in a <strong>void function</strong> I get this:</p>
  
  <blockquote>
    <p>The body cannot be a iterator block because void is not a iterator
    interface type.</p>
  </blockquote>
  
  <p>If I set animation to <strong>true</strong> and never set it back to <strong>false</strong>, it works - but not as expected because obviously animation goes forever.</p>