• 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 /
  • Help Room /
avatar image
0
Question by LabyrinthOfDreams · Sep 06, 2015 at 10:04 PM · java

Im new so if you're ganna flame me then don't read this

So I just started learning Unity and Java at the same time, and I'm a rank 1 newbie. The project I'm working on has a ball that moves side to side on a flat plane with the ability to jump. I'm writing this in Unity 5.1 and the tutorial I'm watching is in Unity 4.x. I have the exact code of the tutorial copied down, but being new to Java I have no way of knowing why Unity 5.1 is not accepting the code, nor do I have a direction in which I can start to look.

Here are the errors I am receiving: Assets/MoveBall.js(13,26): BCE0043: Unexpected token: ). Assets/MoveBall.js(13,27): BCE0044 expecting ), found '.'. Assets/MoveBall.js13,28): UCE0001 ';' expected. Insert a semicolon at end. Assets/MoveBall.js(17,26): BCE0043 Unexpected token: ). Assets/MoveBall.js(17,26): BCE0044 expecting ), found '.'. Assets/MoveBall.js(17,28): UCE0001 ';' expected. Insert a semicolon at end.

I don't understand the errors that are appearing. For instance it says that lines 13 and 17 expects a semicolon. but there is clearly a semicolon right there at the end, so I just don't get it. I'm probably not understanding how to read the error messages, but for the life of me I don't even know how to ask google what I am doing wrong, and this is driving me insane because i literally just picked this up and it's already broken.

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 LabyrinthOfDreams · Sep 06, 2015 at 10:05 PM 0
Share
 #pragma strict
 
 var rotationSpeed = 100;
 var jumpHeight = 8;
 
 private var isFalling = false;
 
 function Update ()
 {
 //handle ball rotation
 var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
 rotation *= Time.deltaTime;
 GetComponent<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
 
 if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W))
 {
 GetComponent<Rigidbody>().velocity.y = jumpHeight;
 }
 }

Code came out wrong in post

2 Replies

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

Answer by Positive7 · Sep 06, 2015 at 10:37 PM

 GetComponent<Rigidbody>()

to

 GetComponent.<Rigidbody>()

note the dot after GetComponent it required in java

Comment
Add comment · Show 3 · 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 LabyrinthOfDreams · Sep 06, 2015 at 11:05 PM 0
Share

Awesome, it's no longer saying there are any errors and when i press play it goes into game mode like it is supposed to... only problem now is that the ball still wont move :/

avatar image Positive7 · Sep 06, 2015 at 11:15 PM 0
Share

Do you get any error? It does move on my test scene. Did you attach script to the ball? Does it have a Rigidbody? Does Is$$anonymous$$inematic unchecked?

avatar image LabyrinthOfDreams · Sep 07, 2015 at 12:10 AM 0
Share

Ok that was it, somehow the script was unattached from my ball, which is weird because I didn't delete my script or my ball. Regardless thank you Positive7 you are amazing :)

avatar image
0

Answer by ransomink · Sep 06, 2015 at 11:03 PM

It's because you're using JavaScript; GetComponent<Rigidbody>() works for C#, but not JS. You have to place a "." after GetComponent. Here are the two ways you can write this:

 GetComponent.<Rigidbody>().AddRelativeTorque(Vector3.back * rotation);

or

 GetComponent(Rigidbody).AddRelativeTorque(Vector3.back * rotation);
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

29 People are following this question.

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

Related Questions

Android Plugin and StepSensor, Why my methods on java arent called from my c# script? 0 Answers

How to load android activity when the button clicked in unity scene? 0 Answers

No Java runtime present, requesting install. 1 Answer

How do I get string from a list using get? (Java) 0 Answers

Google Cast - Android Build fails 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