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 venhip · Jul 08, 2012 at 05:33 AM · functionsfoundexpecting

Various Code errors, found X was expecting Y, missing ";", and "can't declair functions on the fly"

My code, as good as i can do, probably not the best but ya'know. anyway, Its giving me grief in the console in Unity, telling me to swap ='s for :'s ect. So can someone have a look see whats up? Thanks!

I get these errors: (17,18) expecting(, found 'OnMouseOver'. (19,9) Unexpected token: if. ( 21,20) expecting :, found '='.

 var maxDist : float;
 var forceStrength = 10.0;
 var reverseStrength = -10.0;
 private var applyForce = false;
 private var reverseForce = false;
 
 
 function Awake()
 {
     var hit : RaycastHit;
     if(Physics.Raycast(transform.position, transform.forward, hit, maxDist))
     {
         if(hit.transform.tag == "Dynamic")
         {
             function OnMouseOver();
             {
                 if(Input.GetMouseButton(0));
                 {
                     applyForce = true
                 }
                 else
                 {
                     applyForce = false;
                 }
                 if(Input.GetMouseButton(0))
                 {
                     reverseForce = true;
                 } 
                 else 
                 {
                     reverseForce = false;
                 }
             }
         }
     
         function OnMouseExit()
         {
             applyForce = false;
             reverseForce = false;
         }
     }
 }

Thanks.

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 whydoidoit · Jul 08, 2012 at 07:42 AM 2
Share

Could you edit your question title and make it something that might be useful to a future searcher? Unity Answers is a $$anonymous$$nowledge Base and as such it should have questions that are meaningful.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Jul 09, 2012 at 12:59 PM

You can't declare functions on the fly. This is not a dynamic scripting language, it's a compiled language. UnityScript works way different to the JavaScript you might know from website developing.

I guess you want something like that:

 var maxDist : float;
 var forceStrength = 10.0;
 var reverseStrength = -10.0;
 private var applyForce = false;
 private var reverseForce = false;
 
 
 function OnMouseOver()
 {
     var hit : RaycastHit;
     if(Physics.Raycast(transform.position, transform.forward, hit, maxDist))
     {
         if(hit.transform.tag == "Dynamic")
         {
             applyForce = Input.GetMouseButton(0);
             reverseForce = Input.GetMouseButton(0);
         }
     }
 }
 
 function OnMouseExit()
 {
     applyForce = false;
     reverseForce = false;
 }
Comment
Add comment · 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
3

Answer by delstrega · Jul 08, 2012 at 07:14 AM

From what I can tell, you are defining the OnMouseOver() function inside of Awake() which of course doesn't work. Additionally there's a semicolon at the end of this line:

 function OnMouseOver();

And from the looks of your code it seems to me, that the parentheses got wrong.

All those things confuse the compiler and lead to stupid error messages like the one you mentioned. So try to go through your code again and fix parentheses, semicolons and the order of stuff and you should be fine.

Comment
Add comment · Show 16 · 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 venhip · Jul 08, 2012 at 07:36 AM 0
Share

Thanks, I can be too messy for my own good lol, the problem now is that I need to define On$$anonymous$$ouseOver within Awake so that the "dynamic" shapes will register the mouse hover on them, I don't know how else you'd do it D:

avatar image whydoidoit · Jul 08, 2012 at 07:43 AM 0
Share

I've converted your answer to a comment, Answer on UA means Solution and not Reply - there's an Add New Comment button hidden on the right of the screen.

avatar image Wolfram · Jul 08, 2012 at 11:59 AM 3
Share

There's still a ';' at the end of if(Input.Get$$anonymous$$ouseButton(0));

avatar image Linus · Jul 08, 2012 at 12:51 PM 3
Share

Hope you got it working. Dont forget to spread some karma and maintain structure on the site by selecting best answer

avatar image delstrega · Jul 08, 2012 at 02:01 PM 1
Share

$$anonymous$$aybe that's because Awake() is only called once at the beginning, try moving that piece of code into On$$anonymous$$ouseOver().

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

BCE0044: expecting :, found 'if' ??? 1 Answer

Expecting :, found ; and can't figure it out... 2 Answers

Error Java script 1 Answer

BCE0044: expecting '"', found '\r'. 1 Answer

So many script problems. Please help, urgent! 2 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