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 TUTOCF · Jun 11, 2017 at 12:20 PM · collisionintremoveintegeradding

Does my script become stupid, or do I become stupid?

Hi everyone, I've got a bad problem with my script.

 public void OnCollisionEnter(Collision other)
     {
         if(other.gameObject.name == "down")
         {
             result = result -= 1;
             print(result);
             StartCoroutine(waiterDown());
         }
         if (other.gameObject.name == "up")
         {
             result = result += 1;
             print(result);
             StartCoroutine(waiterUp());
         }
     }

Here's the part of the code that I don't understand. If the object touches "up", it adds to the integer value "result" +1, but if it touches "down", it removes -1 to the integer value "result". BUT...! In the console, I see instead of "5, 4, 5, 4, 3, 2, 3..." this "0, 1, 2, -1, -2, 3.."!! That has no sense! If someone can help me, it'll great! I'll test all your propositions. 2 - 1 doesn't make -3!

And I forgot to say that I'm not a native English speaker, that's why my English isn't very good... Thanks!

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 TUTOCF · Jun 11, 2017 at 06:21 PM 0
Share

Any ideas?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Major · Jun 11, 2017 at 10:29 PM

I'm not 100% sure how this script works with your scene, but there are some unusual syntax parts that may have something to do with it.

On lines 5 and 11 you have this:

 result = result -= 1 or 
 result = result += 1

This doesn't make sense because you are using assignment operators inside of an assignment operator. Anything with an '=' sign in it, is an assignment operator. In essence, you are assigning a value to result twice in each respective instance, and without more knowledge on how this works I have to assume that this might have something to do with it. What you mean here is this:

 result -= 1 or 
 result += 1
 
      or
 
 result = result - 1 or
 result = result + 1

This is really the only way I can help because I do not fully understand how this script is being interacted with, and how the functions in this script are used.

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 TUTOCF · Jun 16, 2017 at 05:08 AM 0
Share

Thanks mate!!

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

140 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 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 do you add values of int healthValue on collision with a gameObject Coin in a 3d world?? 1 Answer

String to int conversion not working in ControllerCollider method although I am sure it is an int... 1 Answer

How to remove parts from a string 1 Answer

Sync Var not syncing on client. 0 Answers

NullReferenceException: Object Reference not set to an instance of an object 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