[JavaScript Error] BCE0043: Unexpected token:

I’m a noob…
This is the errors i got

  1. Assets/Txt.js(2,1): BCE0043: Unexpected token: [.
    2)Assets/Txt.js(5,1): BCE0043: Unexpected token: ].
    3)Assets/Txt.js(9,2): BCE0043: Unexpected token: [.
    4)Assets/Txt.js(12,2): BCE0043: Unexpected token: ].
    I’m doing a start menu for my game…
    This is my code

    function OnMouseEnter()
    [
    //change the color of text
    renderer.material.color = Color.red
    ];

    function OnMouseExit()
    [
    //change the color of text
    renderer.material.color = Color.white
    ];

Your immediate problem is that you use [ and ] when you should be using { and }.

Functions doesn’t end with ;


I’d strongly recommend that you try to learn how to program with Unitys Javascript.

If you search answers for help on learning Javascript for Unity, you’ll find a lot of resources.

Here’s one, for example: [How can i learn JavaScript (UnityScript) ?][3]


Some things to keep in mind when you look for tutorials or books regarding Unitys JavaScript.

  • It’s often called UnityScript, to solve an ambiguity with other languages that are named similarly.
  • So avoid confusion with
[1]!
 - So avoid confusion with [Java][2]!

Hope it helps. Good luck, and pick a nice site to start learning programming.

  [1]: http://en.wikipedia.org/wiki/JavaScript
  [2]: http://en.wikipedia.org/wiki/Java_(programming_language)
  [3]: http://answers.unity3d.com/questions/238630/how-can-i-learn-javascript-unityscript-.html

Wrong brackets, and you don’t need semicolon after closing bracket. You do however need a semicolon after each “INSTRUCTION (F U @Vexe)”.

function OnMouseEnter()
{
    renderer.material.color = Color.red;
}