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 DaNova · Jan 22, 2017 at 02:37 PM · script.2d-platformer

2D Game Coding Error. I can't find where the error is. Help!!!

The error I receive:

Assets/Scripts/Player.cs(33,74): error CS8025: Parsing error

My Script:

using UnityEngine; using System.Collections;

public class Player : MonoBehaviour {

 public float maxSpeed = 3f;
 public float speed = 50f;
 public float jumpPower = 150f;

 public bool grounded;

 private Rigidbody2D rb2d;

 void Start()
 {
     rb2d = gameObject.GetComponent<Rigidbody2D>();
 }


 void Update()
 {

 }

 void FixedUpdate()
 {
     float h = Input.GetAxis("Horizontal");

     rb2d.AddForce((Vector2.right * speed) * h);

     if (rb2d.velocity.x > maxSpeed)
         (
                rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y))


Any help would be greatly appreciated!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by HAPPY_SIR · Jan 22, 2017 at 03:59 PM

Go into the console tab and click the error. It will show you were the error is. And you have no } at the end of void FixedUpdate().

And you're not using :

 void Update()
  {
  }

so it's pretty much useless

does that help?

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
avatar image
0

Answer by DaNova · Jan 22, 2017 at 04:14 PM

@HAPPY_SIR

It gave me an Ubexpected symbol "}" error, and the previous error still remains

Comment
Add comment · Show 8 · 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 HAPPY_SIR · Jan 22, 2017 at 04:28 PM 0
Share

what if you change

 if (rb2d.velocity.x > maxSpeed)
          (
                 rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y))

to

 if (rb2d.velocity.x > maxSpeed)
     {
                 rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y))
      }


(add the {} symbols and take away the: ) )

avatar image DaNova · Jan 22, 2017 at 04:37 PM 0
Share

@HAPPY_SIR

Still gives me the original error

avatar image HAPPY_SIR DaNova · Jan 22, 2017 at 04:49 PM 0
Share

what if you take away the last ) ? you have one at the start and to at the back .

avatar image HAPPY_SIR HAPPY_SIR · Jan 22, 2017 at 04:52 PM 0
Share

and a ; symbol at the end?

avatar image DaNova · Jan 22, 2017 at 04:53 PM 0
Share

@HAPPY_SIR

I still receive the error

This is what it looks like now after the updates using UnityEngine; using System.Collections;

public class Player : $$anonymous$$onoBehaviour {

 public float maxSpeed = 3f;
 public float speed = 50f;
 public float jumpPower = 150f;

 public bool grounded;

 private Rigidbody2D rb2d;

 void Start()
 {
     rb2d = gameObject.GetComponent<Rigidbody2D>();
 }


 void Update()
 {

 }

 void FixedUpdate()
 {
     float h = Input.GetAxis("Horizontal");

     rb2d.AddForce((Vector2.right * speed) * h);

     if (rb2d.velocity.x > maxSpeed)
     {
         rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
   }
avatar image HAPPY_SIR DaNova · Jan 22, 2017 at 06:11 PM 0
Share

well , the

  void FixedUpdate()
  {
      float h = Input.GetAxis("Horizontal");
 
      rb2d.AddForce((Vector2.right * speed) * h);
 

       if (rb2d.velocity.x > maxSpeed)   **<---- THIS**
       {
           rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
     } **THIS ONE IS THE ENDING OF THE UPDATE VOID**


still dosen't have a } at the end. That one that is out right now is only for the void FixedUpdate() . Try adding another } and make sure it (if (rb2d.velocity.x > maxSpeed) ) has 2. You can click on the symbols ({}) to see the other.

for example:

  void Update()
  { (klick on this one and it will mark the other one so you know they are togheter)
 
  }(or this one)

Voids if and those thing like that will always need one { and one }.

I tried my best to explain . Sorry if you don't understand.

avatar image DaNova · Jan 22, 2017 at 06:21 PM 0
Share

@HAPPY_SIR

I added it and it STILL gives me the error. I have absolutely no clue what it can possibly be. This is so annoying

avatar image HAPPY_SIR DaNova · Jan 22, 2017 at 06:25 PM 0
Share

Well , mabey try re writing the script? you might find something. :/

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

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

How to rotate a Pivot with a front facing Player with a mouse?,Does anyone know the code for front pivot movement using mouse to aim? 1 Answer

hi i want to add a slid and wall jump to my script with animation, i am lost ^^ 0 Answers

[SOLVED] 2d character animation bugging 1 Answer

How to change if you can click a button? 0 Answers

How to make an enemy 2d chasing player? 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