When do I do what?

I’m new to Unity 5 and am taking the Complete Unity 5 Developer class.
I have some questions on scripting.

  1. When does the Start function get executed?
    I am in the middle of the Brick breaker game.
    What I mean is take this code for example which is in the Brick script.

private int timesHit; // Defined just under the Class definition.
void Start () {
// Initialize number of hits to 0
timesHit = 0;
levelManager = GameObject.FindObjectOfType();
isBreakable = (this.tag == “Breakable”); // When a brick first comes into existence can be Breakable.
if (isBreakable) {breakableCount++;}
}
Does the timesHit = 0 command in the Start function run each time a brick is hit for the first time? If it does, the timesHit variable is updated for each new hit.
How is the timesHit variable associated with a given Brick?

  1. There is a manual and an API reference document that you can use to determine how to use APIs. Is there any type of document where you can search for what you want to do and when and if found, gives you one or more APIs that may help you do what you need?

  2. Is there anything I can read to help me determine in which script code should be written?
    Ex. A ball collides with a brick. The collision affects both items. The ball has a script and the brick has a script. If you are doing a onCollisionEnter2D how do you determine where the code goes? I understand, that if you want to know how many times a brick is hit the collider code should be in the brick script but what if it isn’t so cut and dry? Do you use trial and error or is there some sort of logical methodology?

  3. When would you use a public vs. a private variable? Can you define a Static variable within a function?

  4. When you create a variable within a function, it gets reset each time you enter the function. Is that correct?

1,2,3
the docs can answer most of your questions. Unity - Scripting API: MonoBehaviour.Start()
most functions feature sample code, also try the learn section for more in depth examples.
Learn

4,5
public variable can be accessed outside of a class where private can only be used from within the class.
a lot of what your asking is general programming stuff, google really is your friend here.

Start happens before the first frame a GameObject is active. In most cases this is when the object is Instantiated.

Google is a great way to search the API

There is sometimes a best place to put each script, but not always. Often you will put the script on both components. OnCollisionEnter on one script might call a method on the other script.

Use private unless you have a reason to use public

You can’t add static to a local scope variable.

Local variables are not reset per se. Rather a new variable is created each time. It’s a pretty narrow distinction, but an important one once you start tossing around things like lambda functions.

Thanks for your response. I will look into what you sent me.

Thanks for the feedback BoredMormon,

Thanks to everyone who replied. I will look into those responses that gave me other places to look.

Thanks for your feedback.

[Resolved]

Thanks to everyone who helped.