- Home /
Converting My JS code into UnityScript
So I recently learnt JavaScript at a beginner level but was able to make some basic things like a fruit machine, dice game and a simple dodging game. But I am trying to figure out the main difference between UnityScript and JavaScript and to do this I thought I would try to import my code and alter it to work with unity.
So this is my issue I created a simple thing to suggest the characters position and alter it when the user presses the left or right key (I am aware many of it is probably wrong but I am learning), however Unity passes some errors which makes me wonder.
The Errors I have received that baffle me are:
PlayerController.js(9,26): BCE0044: expecting ), found '='.
PlayerController.js(9,27): BCE0043: Unexpected token: >.
So to summarise I am asking if this is wrong why? and does this mean Unity does not accept a simple => to check that a variable is equal to or greater than a value/function and if that is the case what should I use instead.
Thank for any help the code is below.
var posX = 0;
var maxLeft = -10;
var maxRight = 10;
function Update()
{
if (Input.GetButton("left"))
{
if (posX => maxLeft)
{
//If the position is equal to maxLeft then it will not do anything.
}
else
{
//Move character left on screen;
posX = posX-0.5;
transform.position = (0, posX, 0);
}
}
else if (Input.GetButton("right"))
{
if (posX => maxRight)
{
//If the position is equal to maxRight then it will not do anything.
}
else
{
//move character right on screen;
posX = posX+0.5;
transform.position = (0, posX, 0);
}
}
else
{
//Left or Right arrow key not pressed so do nothing.
}
}
Answer by Graham-Dunnett · Jun 05, 2014 at 11:46 AM
Well, the errors say the problem is on line 9. Line 9 should be:
if (posX >= maxLeft)
Also, next time, look up the error you get on the tags section of this site.
Your answer
Follow this Question
Related Questions
3 java errors on a basic shooting script? 2 Answers
Please help, syntax error woe 2 Answers
How can solve these errors in my java script 1 Answer