Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Joebear · Nov 29, 2015 at 08:07 PM · unity 5javascripterror

Expecting EOF, found public

So I wrote this script based off of a script that was used in an answer on this website, but I have a problem: Unity says that public is unexpected and it was expecting the EOF. I'm not sure how to fix this since I'm rather new. This is a script for a shooting gun, and I need the projectile to be public, however the word "public" 1;1 is not recognized in the system. Please help, thank you!

public( Rigidbody )projectile;

public float speed = 20;

// Use this for initialization void Start () {

}

// Update is called once per frame void Update () {

  if (Input.GetButtonDown("Fire1"))
  {
      Rigidbody instantiatedProjectile = Instantiate(projectile,
                                                     transform.position,
                                                     transform.rotation)
          as Rigidbody;
      
      instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
      
  }

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by pekalicious · Nov 29, 2015 at 11:42 PM

Why did you put RigidBody in parentheses? I'm just curious to know where you got that idea. Anyway, simply remove them and you should be fine:

 public Rigidbody projectile;
 public float speed = 20;
Comment
Add comment · Show 6 · 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 Joebear · Nov 30, 2015 at 12:06 AM 0
Share

Without the parentheses, I have these two errors: Unexpected token: rigidbody Unexpected token: float ';' expected. Add a semicolon.

I added to parentheses to take those away, however I'm not sure why it doesn't recognize the 'public'.

avatar image Joebear Joebear · Nov 30, 2015 at 12:08 AM 0
Share

Three errors*

avatar image pekalicious · Nov 30, 2015 at 12:55 AM 0
Share

Sounds like you either created a javascript file but copied c# code, or you created a c# script but forgot to create the class definition. What type of script are you going for?

avatar image Joebear pekalicious · Nov 30, 2015 at 01:47 AM 0
Share

I'm going for javascript. I tried copying the script into a C# file, but there are many errors when I do that. When I add a class, it doesn't recognize "Projectile" and "Float." It also wants an extra semicolon.

avatar image pekalicious · Nov 30, 2015 at 01:58 AM 0
Share

Javascript and c# have wildly different syntax. Not to mention that you cannot easily have a javascript class talk to a c# class and vise versa.

Here is a short video explaining the differences: https://unity3d.com/learn/tutorials/modules/beginner/scripting/c-sharp-vs-javascript-syntax

I suggest choosing one type of script and sticking with it. $$anonymous$$y recommendation would be c#, but choose whatever you find easier.

avatar image Joebear pekalicious · Nov 30, 2015 at 02:24 AM 0
Share

Thanks for your help!

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

49 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 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

Errors in my script 0 Answers

Unable to join player connection alternative multicast group. 1 Answer

How to address JavaScript erro in UnityLoader.ja 1 Answer

The body of '' cannot be an iterator block because 'void' is not an iterator interface type??? 2 Answers

Warnings in Java 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