Beginning C# - Part 19: Methods | Ray Wenderlich

In this video, you'll learn how to create methods and call them in your code.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3247-beginning-c/lessons/19

Thank you Brian, this is a very useful series of tutorial, I am understanding a lot of concept I had seen but never quite grasp.
Pierre

Hey Brian,
I just had a question regarding the challenge. Is there a reason you created the new monster in start rather than just creating the new monster during the private variable’s declaration? this is how i went about it …

public int damage;
private Monster monster = new Monster(); // instead of just private Monster monster;
// and then in Start(){ monster = new Monster;

// Start is called before the first frame update
void Start()
{
    monster.SetHealth(100);
    Debug.Log("Health: " + monster.GetHealth());
}

I didn’t run into any compile errors and the code functioned as it should have in Unity, so I guess I’m really asking, would the manner in which I have written my code pose problems in other areas for the future? Is there a specific reason, regarding whatever is happening “under the hood” as to why you created the new monster in the Start() method?

Thanks again these videos are terrific, and the feedback is appreciated more than you may know.

Sincerely;
Deprogrammer

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]