- Home /
not sure whats happened :S
ive got a custom cursor script from Unify, it works fine at first but im trying to change it depending on what button is pressed.
Except my console is giving me errors like:
Assets/cursorScript.js(71,9): BCE0044: expecting }, found 'else'.
Assets/cursorScript.js(42,4): BCE0043: Unexpected token: ).
Assets/cursorScript.js(142,9): BCE0044: expecting EOF, found '}'.
Assets/cursorScript.js(43,9): BCE0044: expecting ), found '{'.
Any ideas?? :S
im quite new to Java and i understand most of whats in the script ill post my script aswell so you can have a look.
var GrassButton : Texture2D; // The texture for when the cursor isn't near a screen edge var WaterButton : Texture2D; var ForestButton : Texture2D; var CustomCursor : Texture2D;
var nativeRatio = 1.3333333333333; // Aspect ratio of the monitor used to set up GUI elements private var lastPosition : Vector3; // Where the mouse position was last var normalAlpha = .5; // Normal alpha value of the cursor ... .5 is full var fadeTo = .2; // The alpha value the cursor fades to if not moved var fadeRate = .22; // The rate at which the cursor fades private var cursorIsFading = true; // Whether we should fade the cursor private var fadeValue : float;
static var GrassPressed = 0; static var ForestPressed = 0; static var WaterPressed = 0;
// Scale the cursor so it should look right in any aspect ratio, and turn off the OS mouse pointer function Start() { // Slightly weird but necessary way of forcing float evaluation var currentRatio : float = (0.0 + Screen.width) / Screen.height; transform.localScale.x *= nativeRatio / currentRatio; Screen.showCursor = false; fadeValue = normalAlpha; lastPosition = Input.mousePosition;
}
function Update() { var mousePos = Input.mousePosition; // If the mouse has moved since the last update if (mousePos != lastPosition) { lastPosition = mousePos; // Get mouse X and Y position as a percentage of screen width and height MoveMouse(mousePos.x/Screen.width, mousePos.y/Screen.height); } }
function MoveMouse(mousePosX : float, mousePosY : float) { if() { // If the mouse is on a screen edge, first make sure the cursor doesn't go off the screen, then give it the appropriate cursor if (mousePosX < .005) { mousePosX = .005; guiElement.texture = CustomCursor; }
if (mousePosX > .995) { mousePosX = .995; guiElement.texture = CustomCursor; }
if (mousePosY < .005)
{
mousePosY = .005;
guiElement.texture = CustomCursor;
}
if (mousePosY > .995)
{
mousePosY = .995;
guiElement.texture = CustomCursor;
}
transform.position.x = mousePosX;
transform.position.y = mousePosY;
else if (GrassPressed == 1) { // If the mouse is on a screen edge, first make sure the cursor doesn't go off the screen, then give it the appropriate cursor if (mousePosX < .005) { mousePosX = .005; guiElement.texture = GrassButton; } if (mousePosX > .995) { mousePosX = .995; guiElement.texture = GrassButton; } if (mousePosY < .005) { mousePosY = .005; guiElement.texture = GrassButton; } if (mousePosY > .995) { mousePosY = .995; guiElement.texture = GrassButton; }
transform.position.x = mousePosX;
transform.position.y = mousePosY;
}
else if (WaterPressed == 1) { // If the mouse is on a screen edge, first make sure the cursor doesn't go off the screen, then give it the appropriate cursor if (mousePosX < .005) { mousePosX = .005; guiElement.texture = WaterButton; } if (mousePosX > .995) { mousePosX = .995; guiElement.texture = WaterButton; } if (mousePosY < .005) { mousePosY = .005; guiElement.texture = WaterButton; } if (mousePosY > .995) { mousePosY = .995; guiElement.texture = WaterButton; }
transform.position.x = mousePosX;
transform.position.y = mousePosY;
}
else if (ForestPressed == 1)
{
// If the mouse is on a screen edge, first make sure the cursor doesn't go off the screen, then give it the appropriate cursor
if (mousePosX < .005) {
mousePosX = .005;
guiElement.texture = ForestButton;
}
if (mousePosX > .995) {
mousePosX = .995;
guiElement.texture = ForestButton;
}
if (mousePosY < .005) {
mousePosY = .005;
guiElement.texture = ForestButton;
}
if (mousePosY > .995) {
mousePosY = .995;
guiElement.texture = ForestButton;
}
transform.position.x = mousePosX;
transform.position.y = mousePosY;
}
}
}
sorry about it being untidy :/ im not quite perfect at using this site yet :P
Answer by Thomas 7 · May 05, 2011 at 09:48 PM
Might be the fact that you have an empty if statement in your MoveMouse. If thats not the problem you should check if your brackets are placed right and are all closed.
would the empty brackets not activate anyway then the rest act is the parameters are met? or have i got it wrong?
Your answer
Follow this Question
Related Questions
little problem with java script 1 Answer
Javascript Expecting Errors ';' & '=' 0 Answers
Error: expecting ( 1 Answer
Why does if(levelToLoad ==null) not work? 2 Answers
If/else statements working one way, and not the other 0 Answers