Search code examples
javascriptunity-game-engineunityscript

Unity js script not working


I have recently taken an interest into unity, and as I guide a chose a playlist from youtube. I have installed the

Unity 5.6.4

16 Oct, 2017

version as well.

Now, I encounter an error when I try to add a script to an object.

In the tutorial: here , this happens from 11:40 to 13:40.

Basically, as a summary, he is writing a script in js and then attaches it to an object. Now, I have followed the exact steps as him, but it does not work for me.

I write the same script as him, in JS:

jsScript

then add the script to the object. But then, on the object, I should get a target option, like he does:

enter image description here

However, I don't get this option on my object:

enter image description here

The error I get in the console is this:

Assets/Scripts/PickUp.js(1,386): BCE0044: unexpected char: 0xFEFF.

And this is the actual script:

var target : Transform; 
function Update () { } 

function OnMouseDown () 
{ 
    this.transform.position = target.position; 
    this.transform.parent = GameObject.Find("FPSController").transform; 
    this.transform.parent = GameObject.Find("FirstPersonCharacter").transform; 
} 

function OnMouseUp () 
{ 
    this.transform.parent = GameObject.Find ("FPSController").transform; 
    this.transform.parent = null;
}

Now, I've heard that it is not the most efficient, but at this point, I don't really care about that, I just want it to work.


Solution

  • Try to save your script using UTF8 - no BOM (ByteOrderMark). If that does not help, save as Ansi and try that - or read up what unity wants :)

    enter image description here

    Unity3d Issue Tracker: textassets-encoding-prefab-with-utf8-bom-encryption-is-corrupted it might be related.

    This UTF-8 as default in Unity3D new script? was not solved unfortunately.