I've a problem


That’s not really how a script should look like :slight_smile:

A newly created Unity C# script usually looks like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
      
    }

    // Update is called once per frame
    void Update()
    {
      
    }
}

It’s also important to note that voids like Update have to be written with an uppercase letter at the beginning.

If you’re new to Unity and C# scripting, check out this course:

Adding to the above post, unless you have a specific 2D issue or question, please post scripting issues on the dedicated scripting sub-forum here.

I’ll move your post for you.

Thanks.

You also have a < in the walk code on line 18 in the Update Function

As others said: you cant just write “whatever” and expect it to work. There is syntax and semantic you have to pay attention to. Every single symbol counts, and changing any of them will break the program. That goes for identifiers (names), brackets, placing variables out of scope, or using the wrong symbols in the wrong places. It all follows a certain logic however, so it’s easy once you get a grasp on the basics.

Ill just list the problems with the script you posted real quick:

  • Variable declarations go inside the class. The class body is defined through the curles brackets {}. Currently the compiler is probably extremely confused by what you might even mean with lines 5-7
  • Update() is not the same as update()
  • You cant just put a random . at the end of a line. You want a ; there.
  • Rigidbody has a velocity attribute. Velocity does not exist.
  • The random < will also prevent compilation

If you post code in the future, please dont do so using a screenshot, but instead use code tags!
If you have a problem, describe the problem. Dont just open a post with the most generic title you can think of, put no text there, post a screenshot, and assume all of your problems will just disappear. That’s lazy.
Also you have an error. I mean in this instance, there is so much wrong that it does not matter. But in general, you want to post the full error message when posting a problem.

You are new and that’s fine. However, you need to start with a veeery basic tutorial.
These are simple typos and conceptual misunderstandings of how programming works in general.

There is tons of good entry points, i personally recommend Sebastian Lagues introduction to game development:

1 Like