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

  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.

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.

9655034--1373927--upload_2024-2-20_13-46-0.png

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.

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.

Thank you for responding! I appreciate it.

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:

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

But then the truck never moves.

Your component is simply disabled. See the checkbox to the left of of the component’s name “PlayerController (Script)”? Enable it :wink:

Disabled components aren’t updated by Unity, so your code to move the truck is currently not executed at all.

2 Likes

Wow, thank you. Correct answer!

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.

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.