Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 port1 · Aug 17, 2013 at 08:37 PM · javascripterroroncollisionenterdoorsyntax

Simple syntax error that I can't seem to find

So I am using this script to travel between scenes, however it says that there are 3 errors with placing ;'s and }'s but i have already placed them, please help.

 #pragma strict
 
 var Scene : int = 0 ;
 
 
 function OnCollisionEnter(my_collider : Collision)
 {
 if(my_collider.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.E));
 {
 Application.LoadLevel(Scene):
 }
 }
Comment
Add comment · Show 2
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 Eric5h5 · Aug 17, 2013 at 11:06 PM 0
Share

You can't put Get$$anonymous$$eyDown inside OnCollisionEnter, since it's unlikely that someone could press the key down during the same frame that the collision occurs. Also, use CompareTag when comparing tags ins$$anonymous$$d of using string comparisons (more efficient).

avatar image port1 · Aug 18, 2013 at 02:11 AM 0
Share

so what should I use ins$$anonymous$$d of OncollisionEnter? Or do you have any tips on how I should write this piece of code?

2 Replies

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

Answer by william9518 · Aug 17, 2013 at 09:25 PM

Lots of errors I can see :3. I will just type new code for u instead:

 #pragma strict
  
 var Scene : int = 0;
  
 function OnCollisionEnter(my_collider : Collision){
     if(my_collider.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.E))
     {
         Application.LoadLevel(Scene);
     }
 }

Please do try to use some formatting next time.

STUFF I EDITED:

Do not put a semicolon at the end of an if statement. That alone caused 3 errors because a semicolon ends a statement, but with if in front, so that is an error. Since it ends the statement, the curly brackets circling the if block are no longer part of the if, and are problems.

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 port1 · Aug 17, 2013 at 10:12 PM 0
Share

Thanks, I have no formal school and am currently learning by experimenting, Sorry.

avatar image port1 · Aug 17, 2013 at 10:12 PM 0
Share

*schooling

avatar image william9518 · Aug 17, 2013 at 10:47 PM 0
Share

click the checkmark to accept this as an answer.

avatar image
0

Answer by IgorAherne · Aug 17, 2013 at 08:42 PM

substitute : with ; at line 10

Comment
Add comment · Show 2 · 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 port1 · Aug 17, 2013 at 08:56 PM 0
Share

i accidentally type that here in the actual code it is a ;

avatar image port1 · Aug 17, 2013 at 08:58 PM 0
Share

I accidentally typed that here in the actual code it is a ; any other errors?

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

18 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

Related Questions

Script error with turrets 5 Answers

Syntax errors? 2 Answers

Javascript syntax errors with basic expressions 2 Answers

Cannot remove a prefab using OnCollisionEnter function. 1 Answer

Calling a function from another script issue 1 Answer


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