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 /
avatar image
1
Question by kittehmunsterz · Dec 09, 2016 at 06:19 AM · errorvoid

Ello, i'm new to unity but I keep getting this error in my script?

using UnityEngine; using System.Collections;

public class character : MonoBehaviour {

 //movement variables
 public float maxspeed;

 Rigidbody2D myRB;
 Animator myAnim;
 bool facingRight

 // Use this for initialization
 void Start () {
     myRB = GetComponent<Rigidbody2D> ();
     myAnim = GetComponent<Animator> ();
 
     facingRight = true;

 }

 // Update is called once per frame
 void FixedUpdate () {
     float move = Input.GetAxis ("Horizontal");
     myAnim.SetFloat ("speed", Mathf.Abs (move));

     myRB.velocity = new Vector2 (move * maxspeed, myRB.velocity.y);

     if (move < 0 && facingRight) {
         flip ();
     } else if (move < 0 && facingRight) {
         flip ();
     }
 }

 void flip() {
     facingRight = !facingRight;
     Vector3 theScale = transform.localScale;
     theScale.x *= -1;
     transform.localScale = theScale;
 }

}

Comment
Add comment · Show 8
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 DoubleIsLoveDoubleIsLife · Dec 09, 2016 at 08:25 AM 0
Share

... so what's the error your getting?

avatar image kittehmunsterz DoubleIsLoveDoubleIsLife · Dec 10, 2016 at 01:35 AM 0
Share

Unexpected symbol `void' in class, struct, or interface member declaration was the error, when I posted this I thought I had posted that as well

avatar image Paul17041993 kittehmunsterz · Dec 10, 2016 at 04:13 AM 0
Share

Refer to my answer below.

Show more comments
Show more comments
avatar image Kossuranta · Dec 09, 2016 at 08:57 AM 0
Share

Would help if you tell us what the error is, but at least you are missing ; after bool facingRight.

Also you have exactly same condition in if and else if :)

avatar image kittehmunsterz Kossuranta · Dec 10, 2016 at 01:34 AM 0
Share

Unexpected symbol `void' in class, struct, or interface member declaration was the error, when I posted this I thought I had posted that as well

avatar image RobAnthem · Dec 10, 2016 at 01:37 AM 0
Share

Sometimes Notations can cause errors, try removing the unity-generated notations and running it.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Paul17041993 · Dec 10, 2016 at 04:12 AM

You're missing a semicolon ( ';' ) at the end of "facingRight", so the compiler thinks the "void" statement at the start of the "Start" function is continuing on the same line.

Comment
Add comment · Show 1 · 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 RobAnthem · Dec 10, 2016 at 04:22 AM 0
Share

+1, the rest of us should of actually put it in a compiler before commenting :P

avatar image
0

Answer by aditya · Dec 09, 2016 at 08:56 AM

you haven't post the error so this is just a guessing game and my guess is that the below line is the culprit

 myAnim.SetFloat ("speed", Mathf.Abs (move));

because SetFloat takes float as argument and you are using Mathf.Abs which returns an int .... you can try replacing that line with below line

 myAnim.SetFloat ("speed", (float)Mathf.Abs (move));
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 RobAnthem · Dec 09, 2016 at 10:50 AM

I'm going to guess perhaps his axis always = 0? As it should look more like.

     float move = Input.GetAxis("Horizontal") * speed;

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with script 1 Answer

ANSWERED Unexpected symbol 'void' - I am new to coding please help me find the error 1 Answer

help please 2 Answers

Weird Error c# 1 Answer

Unexpected symbol `void' in class, struct, or interface member declaration 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