Search Unity

Resolved Lesson 2.4 - Collision Decisions Help Please

Discussion in 'Getting Started' started by Ghost-Bunny, Jan 7, 2024.

  1. Ghost-Bunny

    Ghost-Bunny

    Joined:
    Jan 9, 2022
    Posts:
    5
    So, I'm doing Lesson 2.4 - Collision Decisions Part 2 and this code was supposed to spawn animals automatically in a few seconds. I ran, waited, and retyped this several times but it kept telling me "It cannot be called." What did I do wrong?


    upload_2024-1-7_1-29-15.png
     
  2. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    The SpawnRandomAnimal function definition should not be inside the Update function.

    Code (csharp):
    1. void Start()
    2. {
    3.     ...
    4. }
    5.  
    6. void Update()
    7. {
    8.    
    9. }
    10.  
    11. void SpawnRandomAnimal()...
    It's actually valid to define functions inside other functions, but not useful in this case.
     
  3. Ghost-Bunny

    Ghost-Bunny

    Joined:
    Jan 9, 2022
    Posts:
    5
    That worked! Thank you!
     
  4. rgarand64

    rgarand64

    Joined:
    Feb 17, 2022
    Posts:
    15
    Maybe you can tag it as resolved ? So others dont waste time reading question over again...
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,473