Search Unity

Lesson 5.2 Create with Code

Discussion in 'Community Learning & Teaching' started by HCDurston, Aug 28, 2020.

  1. HCDurston

    HCDurston

    Joined:
    Dec 7, 2014
    Posts:
    4
    I am using Unity 2018.4 and Visual Studio 2017. I am at the end of part 6 and to the best of my knowledge have typed everything in correctly. When I run the game to check to see if 5 is added to the score what happens is the score remains at zero and I get the following message:
    NullReferenceException: Object reference not set to an instance of an object
    Target.Start () (at Assets/Scripts/Target.cs:19)
    I checked that everything was typed correctly for that line of code:
    gameManager = GameObject.Find("Game Manager").GetComponent<GameManager>();
    The scoreText object is set correctly on the gameManager object. I can't figure out what I did wrong. Please help.
     
  2. HCDurston

    HCDurston

    Joined:
    Dec 7, 2014
    Posts:
    4
    I solved this myself. Just a simple typing error. Doh! Thanks for checking this post out!
     
  3. unity_4Dzw1sSOoGTxjw

    unity_4Dzw1sSOoGTxjw

    Joined:
    Jan 21, 2021
    Posts:
    1
    what was the error I'm having the same problem
     
  4. Jana_1234

    Jana_1234

    Joined:
    Feb 22, 2021
    Posts:
    1
    what was the issue cause im having the same problem
     
  5. brettlink307

    brettlink307

    Joined:
    Dec 7, 2023
    Posts:
    1
    For me i accidentally had two game manager scripts on the "Game Manager" smh