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
-1
Question by RovenGamer · Jul 02, 2014 at 03:38 PM · errorcompilerelse

'else' not working.... please help:(

the script I have is not working when I'm pretty sure it should be but when I try to play it, it says Assets/SCRIPTS/character script.js(20,1): BCE0044: expecting }, found 'else'. someone please help, its very frustrating while still trying to learn coding..

 #pragma strict
 
 var rotationSpeed : float = 10;
 var walkSpeed : float = 7;
 var gravity : float = 50;
 private var yRot : float;
 
 function Update () {
     var Controller : CharacterController = GetComponent(CharacterController);
     var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
     var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
     
 if
     (Input.GetAxis("Vertical")) (Input.GetAxis("Horizontal"));
     {
     animation.CrossFade("Run", 0.2);
         Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
         Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
     }
 else 
     {
         animation.CrossFade("Idle", 0.2);
     }
     
 if
 (Input.GetAxis("Mouse X")){
     yRot += 10 * Input.GetAxis("Mouse X");
     }
     {
     transform.rotation = Quaternion.Euler(0, yRot, 0);
     }
 

the 'else' is on line 20...

Comment
Add comment · Show 1
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 Nick4 · Jul 02, 2014 at 05:58 PM 0
Share

Format your code for gods sake.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by perchik · Jul 02, 2014 at 04:59 PM

Update:

your code is just flat out wrong. What are you trying to do? Input.GetAxis() returns a float between -1 and 1. So the comparison I wrote below fails because you have to compare floats to something.

Perhaps:

 if( Input.GetAxis("Vertical") >.5f && (Input.GetAxis("Horizontal") >0 )

but that may not do what you want.


old post

Everyone who answered (including me) this made typos.

This is your problem:

 if
     (Input.GetAxis("Vertical")) (Input.GetAxis("Horizontal"));

You have a semicolon at the end, but when you get rid of it, it's going to throw more errors.

Removing the semicolon:

 if (Input.GetAxis("Vertical")) (Input.GetAxis("Horizontal"))

Then, @insominx is correct, that's still bad syntax (but their answer has an extra paren too). If you mean to check if one OR the other, do this:

 if (Input.GetAxis("Vertical") || (Input.GetAxis("Horizontal") )

if you want to check to see if BOTH of them:

 if( Input.GetAxis("Vertical") && (Input.GetAxis("Horizontal") )


Notice the parentheses, Input.GetAxis() has one set of parens, the if statement has two.

Comment
Add comment · Show 3 · 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 roojerry · Jul 02, 2014 at 05:07 PM 1
Share

You have pointed out the obvious syntax errors, but this statement should still fail to compile as there is no comparison happening here. Those calls to Input.GetAxis are returning floats.

@RovenGamer needs to figure out what should be compared within that if statement, while learning the proper syntax for if statements

avatar image RovenGamer · Jul 02, 2014 at 05:53 PM 0
Share

it still doesnt recognize the || or the &&.. it says Assets/SCRIPTS/character script.js(13,32): BCE0043: Unexpected token: &&.

avatar image tanoshimi · Jul 02, 2014 at 06:06 PM 0
Share

You didn't even get as far as the rather cryptic lines at the end... :) Basically the whole lot is nonsense.

 if
 (Input.GetAxis("$$anonymous$$ouse X")){
 yRot += 10 * Input.GetAxis("$$anonymous$$ouse X");
 }
 {
 transform.rotation = Quaternion.Euler(0, yRot, 0);
 }
avatar image
0

Answer by GameVortex · Jul 02, 2014 at 03:43 PM

On line 14 you have ended your If statement with a semicolon. The else therefore have no If to belong to. Remove the semicolon and you are good to go.

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 RovenGamer · Jul 02, 2014 at 03:48 PM 0
Share

Nope :( now its also saying "Assets/SCRIPTS/character script.js(14,66): UCE0001: ';' expected. Insert a semicolon at the end."

avatar image
0

Answer by insominx · Jul 02, 2014 at 04:11 PM

Line 13 and 14 look pretty odd:

 if (Input.GetAxis("Vertical")) (Input.GetAxis("Horizontal"));

Maybe you want somethign more like this:

 if (Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")
 {
 ....
 }






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 RovenGamer · Jul 02, 2014 at 04:14 PM 0
Share

ive tried that... it says "Assets/SCRIPTS/character script.js(14,37): BCE0043: Unexpected token: ||."

avatar image
0

Answer by Kiwasi · Jul 02, 2014 at 07:49 PM

As pointed out the code is full of holes. Here is a version that shouldn't throw errors, won't guarantee I've caught everything.

 #pragma strict
  
 var rotationSpeed : float = 10;
 var walkSpeed : float = 7;
 5.var gravity : float = 50;
 private var yRot : float;
  
 function Update () {
     var Controller : CharacterController = GetComponent(CharacterController);
     var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
     var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
  
     if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) {
         animation.CrossFade("Run", 0.2);
         Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
         Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
     } else {
         animation.CrossFade("Idle", 0.2);
     }
  
     if (Input.GetAxis("Mouse X") != 0){
        yRot += 10 * Input.GetAxis("Mouse X");
        transform.rotation = Quaternion.Euler(0, yRot, 0);
     }
 }

My suggestion is to go to the beginner tutorials. You have a desperate need to understand the basics of scripting

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 RovenGamer · Jul 02, 2014 at 08:07 PM 0
Share

thank you so much man. and yeah ive been trying to learn how from a bunch of youtube tutorials but im still confused on most of the basics

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

Multiple Cars not working 1 Answer

Why am i getting this error?! 2 Answers

error CS1525, please help 0 Answers

Errors when trying to play my project 3 Answers

please help island demo compieler error 2 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