Search Unity

Question Junior Programmer: Create with Code 1 - Lesson 1.2.3 Vehicle does not move

Discussion in 'Getting Started' started by TLMunyon, Feb 20, 2024.

  1. TLMunyon

    TLMunyon

    Joined:
    Nov 9, 2023
    Posts:
    8
    1. I make sure the script is connected to the red pickup.
    2. I check several times to make sure my script is identical to Lesson 1.2.3.
    3. I save the file.
    4. The red pickup doesn't move.

    upload_2024-2-20_13-53-9.png

    Lines 8 and 14, "Start" and "Update" were formerly light yellow, but now they are blue.
    Line 17, "Translate" and ";" are light yellow, and the numbers appear to be light green.
    I did not put custom colors on any text.

    Using Visual Studio Community 2022.
    Using Unity 2022.3.13f1.

    The pickup is not moving. Any help would be appreciated.
     

    Attached Files:

  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,928
    Text color has zero influence over how the code works or whether it works at all. It's just Visual Studio highlighting it to make it more readable for you.

    Based on your description, this should definitely work. Double check that the script is added to the pickup, check if there are any errors popping up in the console.
     
  3. TLMunyon

    TLMunyon

    Joined:
    Nov 9, 2023
    Posts:
    8
    The reason I mentioned the text color is because I think the text sometimes changes color when you save the file.

    The screen capture in my first post is what appears in Visual Studio when I double-click: Script > PlayerController in the screen capture below.

    upload_2024-2-21_8-11-15.png

    Thank you for responding! I appreciate it.
     
  4. TLMunyon

    TLMunyon

    Joined:
    Nov 9, 2023
    Posts:
    8
    One more bit of information.

    When I press the play button in either Scene or Game mode, the following window appears for a few seconds:

    upload_2024-2-21_8-21-49.png

    But then the truck never moves.
     
  5. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,928
    Your component is simply disabled. See the checkbox to the left of of the component’s name “PlayerController (Script)”? Enable it ;)

    Disabled components aren’t updated by Unity, so your code to move the truck is currently not executed at all.
     
    TLMunyon and bugfinders like this.
  6. TLMunyon

    TLMunyon

    Joined:
    Nov 9, 2023
    Posts:
    8
    Wow, thank you. Correct answer!
     
  7. TLMunyon

    TLMunyon

    Joined:
    Nov 9, 2023
    Posts:
    8
    Just as a follow-up to this post, in lesson 1.2.1, at 3:50 in the video, when the trainer used the mouse to drag the script and drop it onto the truck, the checkmark to enable the script was already there. It appeared to be enabled by default.
     
  8. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,928
    Yes, scripts are enabled by default. You must have disabled it by accident.

    They can also disable themselves when there’s an exception raised, but that’s unlikely in your case since the script is really simple. A weirder possibility is animation clips animating the value of the checkbox at runtime, but this is even less likely.
     
    Last edited: Feb 21, 2024