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

How to build a wasd and space bar oriented movement

Discussion in 'Scripting' started by Bluedogman, Jun 14, 2022.

  1. Bluedogman

    Bluedogman

    Joined:
    Jun 14, 2022
    Posts:
    2
    I am have problems with making a 2d cube move
    Here is my code

    void Update()
    {
    if (Input.GetKey(KeyCode.W))
    {
    Transform.Position.y += Vector3.left * Panspeed * Time.deltaTime;
    }
    if (Input.GetKey(KeyCode.A))
    {
    Transform.Position.x -= Vector3.right * Panspeed * Time.deltaTime;
    }
    if (Input.GetKey(KeyCode.S))
    {
    Transform.Position.y -= Vector3.up * Panspeed * Time.deltaTime;
    }
    if (Input.GetKey(KeyCode.D))
    {
    Transform.Position.x += Vector3.down * Panspeed * Time.deltaTime;
    }
    }
    }

    I'm having errors that say 'Transform does not contain a definition for 'Position'
     
  2. Bluedogman

    Bluedogman

    Joined:
    Jun 14, 2022
    Posts:
    2
    All fixed! nvm I don't know how to remove threads so its still on here but I Fixed it
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    EXCELLENT! Yes, capitalization matters... as you found out!

    In the future if you post code, please use code tags!

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    As for the errors, next time this will help you:

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.