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.
}
}
↧