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. Dismiss Notice

Javascript file and class name don't match

Discussion in 'Scripting' started by grunesgryphon, Dec 31, 2014.

  1. grunesgryphon

    grunesgryphon

    Joined:
    Oct 14, 2014
    Posts:
    6
    I'm a complete scrub when it comes to coding, so I'm using someone else's teleport script:
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. function Start () {
    4.  
    5. }
    6.  
    7. var target : Transform;
    8.  
    9. function Update () {
    10.  
    11. }
    12.  
    13. function OnTriggerEnter (col : Collider) {
    14.  
    15.     if(col.gameObject.tag == "teleport") {
    16.         this.transform.position = target.position;
    17.     }
    18. }
    When I try to add it to anything, it says that the script doesn't exist because the file and class name don't match. As far as I can tell, my script doesn't even have a class name. Wat.

    Can someone tell me which things to click on to fix it? (As I said, I can't script for my life and I just started with Unity. The file name is telescript2.js and the scene is called meep.unity.)
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Have you accidentally called the file "telescript2.js.js" ? (check in the directory)
    You dont need extensions in project view
     
  3. grunesgryphon

    grunesgryphon

    Joined:
    Oct 14, 2014
    Posts:
    6
    Nope, that doesn't seem to be the case.
     
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    You sure? SURE? (Check the directory)
    It's the only way i can reproduce the error.
    js scripts' class names are derived from the filename, so there's no way to mismatch them intentionally.
     
  5. grunesgryphon

    grunesgryphon

    Joined:
    Oct 14, 2014
    Posts:
    6




    I'm guessing there's someplace I'm missing...?
    (Sorry, I'm kind of an idiot for Unity right now. Everyone starts somewhere I guess.)
     
  6. PolyDevOfficial

    PolyDevOfficial

    Joined:
    May 13, 2013
    Posts:
    65
    try remaking it. and give it a different name
     
  7. grunesgryphon

    grunesgryphon

    Joined:
    Oct 14, 2014
    Posts:
    6
    Done... still not solved, apparently?
    (might want to mute the audio - i was on skype)
     
  8. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,545
    hmmm what an interesting mystery (an interystery?)

    What about some or all of these:

    adding public before the var -
    1. public var target : Transform;
    removing pragma strict

    removing the update function

    removing the start function (both are empty anyways - just for the troubleshooting)
     
  9. PolyDevOfficial

    PolyDevOfficial

    Joined:
    May 13, 2013
    Posts:
    65
    we can consider this now as a BUG! i don't know, coz i'm not using Javascript, i'm more on C#
    and i'm not encountering any problems with scripting

    report this to unity so they can fix this,
     
  10. PolyDevOfficial

    PolyDevOfficial

    Joined:
    May 13, 2013
    Posts:
    65
    Why don't you try it in C# :) maybe it will work
     
  11. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Try uploading the scene so we can take a closer look.
    Make sure all existing script components are removed from that target object before you try adding some of the new ones you made.