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 RebelDragon · Dec 08, 2014 at 04:26 PM · c#2derrorplatformer

2D platformer- getting errors I don't understand (c#)

Hello, I am trying to make a platformer without using premade character controllers. I am running into a lot of errors when I try to run the code, most of which are CS1519: Unexpected symbol (although I've been checking and the symbols look fine!). Here is my code:

     Animator anim;
     Rigidbody2D playerRigidBody2D;
     GameObject gameObject;
 
     // Use this for initialization
     void Start () {
         anim = GetComponent <Animator> ();
         anim.SetBool ("jump", false);
         anim.SetBool ("go", false
         gameObject= GetComponent<Robin>();
         playerRigidBody2D = GetComponent<Rigidbody2D> ();
         
     }
     
     //This huge pile of code is the Move function.
     void Move () {
         Vector3 direction = Vector3.zero;
         //this is jump
         if (Input.GetKey (KeyCode.UpArrow) == true) {
             direction.y += 0.1f;
             anim.SetBool ("jump", true);
             
         }
             else {
                 anim.SetBool ("jump", false)
             }
         
         if (Input.GetKey (KeyCode.RightArrow) == true) {
             direction.x += 0.1f;
             anim.SetBool ("go", true);
         }
         else if (Input.GetKey (KeyCode.LeftArrow) == true) {
             direction.x -= 0.1f;
             anim.SetBool ("go", true);
         } 
             else {
             direction.x= 0f;
             direction.y=0f;
             anim.SetBool ("go",false);
             //That turns everything off if nothing is being pressed.
         }
         gameObject.transform.Translate (direction);
 void FixedUpdate ()
         {
             Move ();
         }
 }


Any help would be greatly appreciated!

P.S: The errors are: 15,22): error CS1525: Unexpected symbol gameObject' (31,25): error CS1525: Unexpected symbol }' (37,20): error CS1525: Unexpected symbol else' (41,28): error CS1519: Unexpected symbol else' in class, struct, or interface member declaration (42,36): error CS1519: Unexpected symbol =' in class, struct, or interface member declaration (43,36): error CS1519: Unexpected symbol =' in class, struct, or interface member declaration (44,38): error CS1519: Unexpected symbol `(' in class, struct, or interface member declaration (47,48): error CS8025: Parsing error

Thank you!

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 KiraSensei · Dec 08, 2014 at 04:32 PM

Hello !

First I advise you to rename your variable "gameObject" because it already is an existing variable (it is the game object that attaches this script).

 anim.SetBool ("jump", false)

should be

 anim.SetBool ("jump", false);

And you declared

  void FixedUpdate ()
  {
      Move ();
  }

Inside the "Move" method, it should be after the last bracket.

Tell me if you have errors after these modifications.

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 RebelDragon · Dec 09, 2014 at 05:42 PM 0
Share

Hello!

I did what you suggested and fixed the anim.SetBool error. I also got rid of the fixed update and renamed the gameObject variable Robin. The error I am getting is error CS1525: Unexpected symbol `Robin'(which is the name of the game object in the hierarchy). So my question is, how do I get Unity to use the game object?

By the way, thank you for answering my post!

avatar image KiraSensei · Dec 09, 2014 at 09:20 PM 0
Share

Please post your new code with the erroneous line.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Error (Read Only) 1 Answer

Simple collision detection C# 2D 1 Answer

How do I fix my compiler errors? (Probably simple to solve) 0 Answers

Make a 2D jump? 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