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 oliver-jones · Feb 26, 2012 at 02:33 AM · raycastvaluesincrease

Increasing A Value Keeps Doubling?!

Hello,

I have a script that detects if my raycast is clicked on a certain object, and when it is clicked, it increases a value by += 1. The problem is, is that my value is increase by 2, not 1?!

Here is my script:

 if(hit.collider.name == "DropUnlock(Clone)" || hit.collider.name == "DropUnlock"){
    print("Drop Unlock");
     if(Input.GetButtonUp("Fire1")){
         Destroy(hit.collider.gameObject);    
         Values.unlocks = Values.unlocks + 1;
     }
 }

Lets say my unlock is currently at 4. When the user clicks on the DropUnlock object, the unlock value changes from 4 to 6, not 5.

Why is this happening?

Thanks

Comment
Add comment · Show 6
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 Eric5h5 · Feb 26, 2012 at 02:56 AM 2
Share

Because you're running it twice, I would guess. By the way, you can do x += 1 ins$$anonymous$$d of x = x + 1, or in the case of x += 1, you can do x++.

avatar image oliver-jones · Feb 26, 2012 at 02:58 AM 0
Share

How am I running it twice? This is inside my Update Function

avatar image Eric5h5 · Feb 26, 2012 at 03:03 AM 2
Share

I don't know, I don't have enough info. :) $$anonymous$$aybe you have the script attached twice.

avatar image oliver-jones · Feb 26, 2012 at 03:09 AM 1
Share

Ah yeah, silly me. I did have the same script twice within my scene. Thanks

avatar image Bunny83 · Feb 26, 2012 at 03:49 AM 1
Share

:D this is what we call science.

Show more comments

1 Reply

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

Answer by robert_mathew · Feb 26, 2012 at 06:04 AM

 var p_hit_break : int;

 function Start ()
    {

   p_hit_break =1; 
    }


  if(hit.collider.name == "DropUnlock(Clone)" || hit.collider.name == "DropUnlock"){
  print("Drop Unlock");
   if(Input.GetButtonUp("Fire1") && p_hit_break ==1 ){
       p_hit_break =2;
       Destroy(hit.collider.gameObject); 
       Values.unlocks = Values.unlocks + 1;

        }
           }

by this method is that my value is increase by 1 as soon as it enter the loop it will become false when ever you want again this condition to work make p_hit_break ==1 so that the condition become true.

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

Shorten Raycast - Line Renderer 3 Answers

Raycast hits and then doesn't fire again? 2D Game Raycasting Problem 1 Answer

How to stop textures flickering 2 Answers

Raycast in Update Incorrect Results When Moving Object 2 Answers

Trying to display object name of raycast hit 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