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 Ragswolf · Jul 14, 2014 at 02:30 AM · errorgamebulletfighting

2D bullet script errors.

I'm currently trying to make a 2d game that allows the player to spawn and launch a bullet, however i'm getting a couple of errors. Specifically the errors are:

"Assets/RangedAttack.cs(26,61): error CS1525: Unexpected symbol `launcher'"

and

"Assets/RangedAttack.cs(54,1): error CS8025: Parsing error"

Any and all help will be greatly appreciated, here is my code:

 using UnityEngine;
 
 public class RangedAttack
 {
     public Bullet bullet;                // reference to bullet prefab to launch
     
     public AttackContext contextStand;         // when attacking while standing
     public AttackContext contextInAir;         // when attacking while in air
     
     public enum ContextId
     {
         eStand = 0,
         eInAir
     }
     
     public class AttackContext
     {
         public string anim = string.Empty;             // animation state name
         public Vector2 bulletStartPosition;            // spawn position of bullet
         public float bulletDirection;                // launch direction
     }
 void update()
 {    
     if (CrossPlatformInput.GetButtonDown("z"))
     {
          FireBullet(UFGPlatformerCharacter2D launcher, ContextId contextId)
         {    
             AttackContext curContext = contextStand;
             switch(contextId)
             {
             case ContextId.eRun: curContext = contextRun; break;
             case ContextId.eInAir: curContext = contextInAir; break;
             }
             
             // make sure move horizontal direction is valid
             float fAngle = Mathf.Deg2Rad * curContext.bulletDirection;
             Vector2 v2MoveDir = new Vector2(Mathf.Cos(fAngle), -Mathf.Sin(fAngle));
             if(launcher.GetMotor().faceRight && v2MoveDir.x < 0f || !launcher.GetMotor().faceRight && v2MoveDir.x > 0f)
             {
                 v2MoveDir.x = -v2MoveDir.x;
             }
             
             // spawn and launch bullet (add player velocity before spawn)
             Vector2 pointPos = launcher.transform.TransformPoint(curContext.bulletStartPosition);
             pointPos = pointPos + (Time.deltaTime * launcher.GetMotor().velocity);
             Bullet newBullet = (Bullet)UnityEngine.Object.Instantiate(bullet, pointPos, Quaternion.identity);
             
             // initiate bullet
             v2MoveDir = launcher.transform.TransformDirection(v2MoveDir);
             newBullet.Setup(launcher, pointPos, v2MoveDir);
             }
         }
     }
 }
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
Best Answer

Answer by Kiwasi · Jul 14, 2014 at 04:21 AM

What's the point of line 26?

If you are trying to declare a method then you need to add a return type first. You also need to move the code outside of update. C# doesn't support nested methods.

If you are trying to call a method you should remove the variable types from inside the parameter list.

If you copied and pasted this code from the net then you really should learn the basics of computer programming before you continue. Check out the beginner tutorials.

Comment
Add comment · Show 5 · 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 Ragswolf · Jul 14, 2014 at 04:35 AM 0
Share

I have a void return type setup in my actual bullet script, this script is meant to instantiate that. But I See now that I never declared it or called it here.

avatar image Kiwasi · Jul 14, 2014 at 04:47 AM 0
Share

Come back once you've tried it in Unity, I'm not confident we have hit all the problems yet.

avatar image Ragswolf · Jul 14, 2014 at 05:18 AM 0
Share

Yes after removing the Update and if functions I just added public void to the firebullet method and it worked fine, but now I have some errors in my bullet code to check out. Thank you for the help though, I really appreciate it. To be honest, I submitted this problem about a week ago but it just now got approved by moderators, so I was kind of in the midst of moving on to a different ranged attack and bullet script for my game.

avatar image Kiwasi · Jul 14, 2014 at 05:19 AM 0
Share

Sorry about the delays. There was something weird going on in the mod queue. You would think a site form computer game programmers would be able to get a website working properly.

avatar image Ragswolf · Jul 14, 2014 at 05:32 AM 0
Share

Haha yeah totally. Oh well though, things happen. Thanks for the help friend. I'll mark the script as solved and work on something new, hopefully when I comeback for some help it won't take a week to get feedback .-.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Error UCE0001 ";"Expected 2 Answers

Multiplayer Script error 2 Answers

error with footsteps script 1 Answer

Main Menu Script Issues 1 Answer

Bullet Fire script not working 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