Search Unity

GameObject.Find() vs explicit declaration? Also good pool manager tutorial?

Discussion in 'Editor & General Support' started by Kaivian, Jun 27, 2019.

  1. Kaivian

    Kaivian

    Joined:
    Jan 18, 2018
    Posts:
    35
    Code (CSharp):
    1.  
    2. public GameObject player;
    3.  
    4. void Start()
    5. {
    6. player = GameObject.Find("player");
    7. }
    8.  
    Ok, so far, I've been doing things the first way. I can't remember where I learned it this way (tic-tac-to maybe? An older youtube video?) I downloaded a project tutorial, and it doesn't use this. It just makes a GameObject and manipulates it.

    Code (CSharp):
    1.  
    2. public GameObject player;
    3.  
    1. Is there a "right" or "wrong" way to be doing this? Or is it specific to use cases? If so, how do I know which to use?

    2. Should this be in Awake()?

    3. Also, I've been just doing tutorials, but haven't seen one that goes over a "pool manager" (for things like bullets). Anyone know of one?

    Thanks!
     
  2. Kaivian

    Kaivian

    Joined:
    Jan 18, 2018
    Posts:
    35
    Should have talked to the rubber duck on this one. Figured out I started doing this for specific components (Like text in canvas groups) and not so much for whole objects, a few mins after I posted this. Still hoping to find info on a pool manager tutorial, or any other insights. :) Thanks