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 user-4565 (google) · Jan 12, 2011 at 12:40 AM · resetactivatedeactivate

How to reset a variable when activated

Im making a FPS and I have several guns. i set it so when the guns are equipped, there is a variable that is deactivated/activated at certain times so the player cant shoot while reloading, or equipping.

I made the gun start where it cant shoot, because the fraction of a second difference between the gun being activated and the animation playing allows the player to shoot, and then switch guns, so then the gun he switched to will start shooting without being equipped. The varibale "abletoshoot" starting at 0 makes the player unable to do this.

The problem is that this only works the first time the weapon is equipped, because "abletoshoot" is not converted back to 0. I was wondering if there is a function thast I can call so when the weapon is activated, set it to 0, or deactivated, set it to 0.

is there such a function to call? activated or deactivated, or possibly something I can use to reset the variable when the weapons are activated or deactivated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Goody! · Jan 12, 2011 at 12:52 AM

Just happened across this question and can't resist answering. I like easy questions. ;)

Put a Boolean in the script that is flipped back and forth from true to false and back again. Like ableToShoot = true/false That seems more straightforward than setting a number.

This post (below) helped me out quite a bit back a while ago. It should show how to set up bools.

AwesomeTutorial

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 user-4565 (google) · Jan 12, 2011 at 02:40 AM 0
Share

well I have the abletoshoot setup and it works fine, but the problem comes in when the weapon is re-activated. This is how it guys

Weapon activated : abletoshoot = 0 until animation finishes weapon deactivated : abletoshoot = 1 so it can shoot weapon re-activated : abletoshoot = 1, it starts off at 1 so the player can shooot while equipping.

I was wondering if there is some way I can reset abletoshoot back to 0 when the weapon is deactivated. How would a boolean work for this? (sorry i have never used booleans before)

avatar image fireDude67 · Jan 12, 2011 at 03:29 AM 0
Share
  • 'I like easy questions':)

avatar image Goody! · Jan 12, 2011 at 08:17 PM 0
Share

@unknown(google), I'd recommend checking out the link I posted above called AwesomeTutorial about scripting. It's long but the reality of Unity is that unless you understand scripting, including booleans, or have someone to do the scripting for you, you won't get far with it. Sorry. :) You can try posting your script up here but most people here won't write it for you if they don't think you have at least a basic grasp on things.

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

No one has followed this question yet.

Related Questions

Can't activate my deactivated GameObjects 1 Answer

Is there any command that can reference deactivated objects? 1 Answer

How to activate a gameobject via scripting ??? 3 Answers

Using OnSceneLoad (additive) to activate script on player within active scene 0 Answers

deactivate and active object, problems 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