Search Unity

Coroutine missing hint and error

Discussion in 'Scripting' started by Patrick222, May 2, 2021.

  1. Patrick222

    Patrick222

    Joined:
    Apr 10, 2021
    Posts:
    1
    If i have a Coroutine IEnumerator ababa() there is no error or hint that something is wrong if i try to call the function ababa() without StartCoroutine(ababa())
    I had to look for hours to find this mistake because i forgot to write StartCoroutine in front of it, maybe it would be nice to implement a message in c# for that.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Bunny83 and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    This is so unnecessary. Use the beauty and power of instantly and immediately putting a Debug.Log() statement into the very start of the coroutine, right at the top.

    Do this always at the very first sign of trouble or question in your mind.

    The instant you did this you would see "Oh man, this code is simply not getting run!"

    And you could LASER-FOCUS 100% your efforts on studying what you expect to run it, eg., the call location, and isolate why it is not running.

    You would look at literally NOTHING else but that issue until your resolve that one issue.

    With that focus, you could also refer to any other successful coroutine anywhere else on the planet and go "Oh, I'm missing the StartCoroutine() wrapper!"
     
  4. ricardobilinski

    ricardobilinski

    Joined:
    Aug 3, 2021
    Posts:
    2
    This is very helpful thank you! I didnt even think to use Debug.Log(). I am going to try this out now.
     
    Kurt-Dekker likes this.
  5. julien83franceschi

    julien83franceschi

    Joined:
    Nov 14, 2020
    Posts:
    233
    Je voudrais dire que si on clique sur un plan alors ne pas déplacer ce dernier .
    Pour cela j'utilise le code suivant :

    Code (CSharp):
    1. if (Input.GetMouseButtonDown(0))
    2.         {
    3.             Rayon = Camera.main.ScreenPointToRay(Input.mousePosition);
    4.             RaycastHit a frappé ;
    5.  
    6.             if (Physics.Raycast (ray, out hit))
    7.             {
    8.                 planeComponent = hit.collider.GetComponent<Plane>();
    9.  
    10.                 if (planeComponent != null)
    11.                 {
    12.                     Debug.Log("Le rayon frappe un objet avec le composant Plane!");
    13.                 }
    14.                 else
    15.                 {
    16.                     Debug.Log("Le rayon touche un objet qui n'a pas le composant Plan!");
    17.                 }
    18.             }
    19.         }
    Le problème, c'est que le compilateur ne reconnait pas 'planeComponent'

    Si vous avez des idées de codes,

    Merci encore,

    A+