Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sean Goddard · May 05, 2011 at 09:33 PM · javascriptif-statementsbce0044bce0043

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 &lt; .005) 
 {
     mousePosY = .005;
     guiElement.texture = CustomCursor;
 }

 if (mousePosY &gt; .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 &lt; .005) {
         mousePosX = .005;
         guiElement.texture = ForestButton;
     }
     if (mousePosX &gt; .995) {
         mousePosX = .995;
         guiElement.texture = ForestButton;
     }
     if (mousePosY &lt; .005) {
         mousePosY = .005;
         guiElement.texture = ForestButton;
     }
     if (mousePosY &gt; .995) {
         mousePosY = .995;
         guiElement.texture = ForestButton;
     }

     transform.position.x = mousePosX;
     transform.position.y = mousePosY;
 }

}

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sean Goddard · May 05, 2011 at 09:36 PM 0
Share

sorry about it being untidy :/ im not quite perfect at using this site yet :P

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sean Goddard · May 05, 2011 at 09:56 PM 0
Share

would the empty brackets not activate anyway then the rest act is the parameters are met? or have i got it wrong?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges