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 MJG1123 · Dec 05, 2015 at 10:50 PM · monodevelopclasstrajectoryparsing

Copy and Pasted code for Trajectory and got one parsing error...

this is where I copy and pasted the code from and when I paste it into unity I get a parsing error around the world extends in the first line

 public static class TrajectoryActor extends Actor {  
     
     private Controller controller;  
     private ProjectileEquation projectileEquation;  
     private Sprite trajectorySprite;  
     
     public int trajectoryPointCount = 30;  
     public float timeSeparation = 1f;  
     
     public TrajectoryActor(Controller controller, float gravity, Sprite trajectorySprite) {  
         this.controller = controller;  
         this.trajectorySprite = trajectorySprite;  
         this.projectileEquation = new ProjectileEquation();  
         this.projectileEquation.gravity = gravity;  
     }  
     
     @Override  
     public void act(float delta) {  
         super.act(delta);  
         projectileEquation.startVelocity.set(controller.power, 0f);  
         projectileEquation.startVelocity.rotate(controller.angle);  
     }  
     
     @Override  
     public void draw(SpriteBatch batch, float parentAlpha) {  
         float t = 0f;  
         float width = this.width;  
         float height = this.height;  
         
         float timeSeparation = this.timeSeparation;  
         
         for (int i = 0; i < trajectoryPointCount; i++) {  
             float x = this.x + projectileEquation.getX(t);  
             float y = this.y + projectileEquation.getY(t);  
             
             batch.setColor(this.color);  
             batch.draw(trajectorySprite, x, y, width, height);  
             
             t += timeSeparation;  
         }  
     }  
     
     @Override  
     public Actor hit(float x, float y) {  
         return null;  
     }  
     
 }  


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 Suddoha · Dec 06, 2015 at 12:41 AM

The code you've posted is Java, so neither completely compatible with C# without a few changes nor the same as UnityScript. It's also neither obvious if you wanted to use this as C# or UnityScript (kind of JavaScript which is NOT Java).

As for the error, C# uses a colon for inheritance instead of 'extends'. But this won't help you much. You also need the base class 'Actor' which is written in Java too (or re-implement that in your TrajectoryActor class) and the ones acting as attributes here, 'Controller, 'ProjectileEquation'. 'Sprite' exists in Unity, but it won't be the one you expect . If you have a closer look at the code, there's also the 'SpriteBatch' class etc. Lot's more to note, for example the annotations (the 'at'Override etc.) aren't supported in C#, that's pretty much Java specific. In order to override methods in C#, you'd need to have a method marked 'virtual' in the base class and override it with the keyword 'override' in the derived class.

I won't continue to list all the differences and difficulties for a proper conversion here, all I can really do is to suggest you to head on to the Unity Tutorial series and when you feel comfortable enough with one of the languages, start implementing this by yourself or find a proper C# source that you can copy most of the things from.

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.

Follow this Question

Answers Answers and Comments

31 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

Related Questions

How to fix this parsing error? 2 Answers

Parsing error 1 Answer

I have this Drag script it works fine but i want it so when you click and drag it follows the mouse like a trail instead of being underneath it, can someone help me please thanks. 0 Answers

Error CS0118: Armor.DisplayName is a property but a type was expected 0 Answers

Editor is Broken 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