Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question error CS0246: The type or namespace name 'transform' could not be found

Discussion in 'Scripting' started by deanbec56, Jun 8, 2021.

  1. deanbec56

    deanbec56

    Joined:
    Apr 28, 2021
    Posts:
    5
    Edit: I ended up figuring this out about 5 minutes after I posted this. It turns out I didn't have a capital letter. I don't know how to delete threads so this is here still... sorry.
     
    Last edited: Jun 8, 2021
  2. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    687
    public Transform teleportTarget; // when it's the *type*, it's capitalized.
    thePlayer.transform.position // when it's an *instance of that type*, it's lower-case.
    Notice how it's after thePlayer and the dot....so it's a property of that gameObject.

    Does not apply to primitive types: int, float, bool, string. Always lower-case.

    I'm sure I'm oversimplifying things and there probably are exceptions (?), but that's the gist.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Sweet! For future reference, remember: NOBODY memorizes error codes. 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.

    The important parts of an 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)

    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.

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855