Javascript file and class name don't match

I’m a complete scrub when it comes to coding, so I’m using someone else’s teleport script:

#pragma strict

function Start () {

}

var target : Transform;

function Update () {

}

function OnTriggerEnter (col : Collider) {

    if(col.gameObject.tag == "teleport") {
        this.transform.position = target.position;
    }
}

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.)

Have you accidentally called the file “telescript2.js.js” ? (check in the directory)
You dont need extensions in project view

Nope, that doesn’t seem to be the case.

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.



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.)

try remaking it. and give it a different name

Done… still not solved, apparently?
(might want to mute the audio - i was on skype)

hmmm what an interesting mystery (an interystery?)

What about some or all of these:

adding public before the var -

  • public var target : Transform;

removing pragma strict

removing the update function

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

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,

Why don’t you try it in C# :slight_smile: maybe it will work

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.