Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Help with 2 lines

Discussion in '2D' started by do_nut, Jan 6, 2014.

  1. do_nut

    do_nut

    Joined:
    Sep 8, 2013
    Posts:
    3
    Hi

    I am learning Unity and C#

    I am using the 2D example (London Bridge) that was released by Unity a while ago

    These two lines are causing problems for me in the Awake function in the Enemy script:

    void Awake()
    {
    // Setting up the references.
    ren = transform.Find("body").GetComponent<SpriteRenderer>();
    frontCheck = transform.Find("frontCheck").transform;
    score = GameObject.Find("Score").GetComponent<Score>();
    }

    Can you please tell me where to find "body" and "frontCheck"

    frontCheck is declared as an variable in the beginning of the script but unfortunately I cannot find body. There is a prefab called body (the hero in the game) but I am not sure if it is that prefab that this script reference to.

    Please advise :)

    Kr
     
  2. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    Hi and welcome to Unity.

    the Find() method looks for gameobjects that match the value passed to it. So in your case, both "body" and "frontCheck" are child members of the enemy prefab. To see this for yourself, just drag the enemy prefab onto your scene and look in your hierarchy.

    $Untitled-1.png
     
  3. do_nut

    do_nut

    Joined:
    Sep 8, 2013
    Posts:
    3
    Yupp got it! Thanks!
     
  4. ChaoticAngel-V

    ChaoticAngel-V

    Joined:
    Mar 30, 2015
    Posts:
    6
    what is the "frontCheck" ?