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
0
Question by Mentalist4006 · May 30, 2011 at 10:14 PM · syntax-errorbce0044bce0043

Formatting problems in Script

I have part of a script that has a syntax problem:

 function Update () {
     
         if (!inFreefall && Input.GetButton("Fire1")) {
            if (transform.forward = Vector3.forward){
               Physics.gravity = Vector3(0, 0, 9.81);
         }
 }

The lines with the second "if" and "Physics" are lines 15 and 16 respectively. Here are the errors:

15: expecting ), found =

15: Unexpected token: )

16: expecting :, found =

What's with this thing?

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 SrBilyon · May 30, 2011 at 10:25 PM

To follow up with SirGive, here is a cleaner/expanded version:

  function Update () 
 {
             if (!inFreefall && Input.GetButton("Fire1")) 
             {
                if (transform.forward = Vector3.forward)
                {
                   Physics.gravity = Vector3(0, 0, 9.81);
                }
              }
     }
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 SirGive · May 30, 2011 at 10:25 PM 0
Share

$$anonymous$$e was explaining the answer without giving it.

avatar image
0

Answer by GlennHeckman · May 30, 2011 at 11:34 PM

1) You were missing a closing bracket "}" for your if statement.

2) When checking for equality, you need 2 "=" signs.

 if(1 == 1)
 {
    // do something
 }

When assigning a value, you use 1 "=" sign.

 a = b;

I fixed your problem below ... Good Luck!

     function Update () 
     {
        if (!inFreefall && Input.GetButton("Fire1"))
        {
           if (transform.forward == Vector3.forward)
           {
                Physics.gravity = Vector3(0, 0, 9.81);
           }
        }
     }
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 SirGive · May 30, 2011 at 11:39 PM 0
Share

bah, I didn't even notice that :P But from his code, it looks like he is missing a bracket.

avatar image SrBilyon · May 30, 2011 at 11:39 PM 0
Share

Lol, totally didn't see the == thing yet, lol!

avatar image Mentalist4006 · May 31, 2011 at 12:29 AM 0
Share

Thanks, I didn't realize that; I'll check it out and let you know.

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

3 java errors on a basic shooting script? 2 Answers

SwipeControl package error in unity iPhone 1.7 1 Answer

scripting problem with if statements 1 Answer

error message for var 1 Answer

Problem with "Pick up key" script 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