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
1
Question by xToxicInferno · Feb 18, 2010 at 12:25 AM · toggleweapon

Weapon Selector

Alright i have two different weapons at the moment, a single shot, and a triple shot. Now i have the 3-way shot set as a power-up. So if i get to the power-up, i got to shoot 3 bullets at once, over just one. That part works, but I want it so that after i get the power-up, it will automatically make it so i can switch from single shot to triple shot at the push of a button (1 and 2). Here is how i thought about doing it, but it doesn't seem to work.

function Update () { if(Input.GetKeyDown("1")) { var weapon = 1; }

if (weapon == 1 ) { if(Input.GetButtonDown("Fire1")) {

The actual code is quite a bit longer so i only grabbed the parts that pretain to it. Also, the if (weapon == 1) part IS in the update function. Now the actual problem with this script is that when i press 1, it seems it does nothing, but if i repeatedly press 1 and fire at the same time, i will randomly shoot 3 amidst lots of single shots. So more or less i want it so it is a toggle. I want it so when weapon is set to 1 it will stay 1 till i click something different.

Lastly, after the checking what weapon is part i have it making the bullets, adding force, and adding random rotation to make them spread. I also have taken a look at the FPS tutorial but it makes no sense to me how they did it.

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
Best Answer

Answer by Sebas · Feb 18, 2010 at 01:32 AM

You set your weapon variable to 1 by pressing "1" (and set to 2 when pressing 2). So far so good.

Now you could check whether the player is firing any weapon and inside this if-statement you would create the two scenarios for 1-shot vs triple-shot. That's pretty much what you have there (just reversed), but if you keep that clean and simple, it should work.

Something like this would be in your update function alongside the if-statements which select your weapon (which you already have).

if(Input.GetButtonDown("Fire1")) {

     if (weapon == 1) {
       //do weapon 1 stuff
     }
     if (weapon == 2) {
       //do weapon 2 stuff
     }

}

You could also combine conditions for your if-statement like such:

if (Input.GetButtonDown("Fire1") && weapon == 1) {
   //do weapon 1 stuff here
}

edit/ It's hard to tell from what your lines of code, but it sounds like you got some if-statements mixed up so that you only shoot 3 bullets when you hit the switch-button and the fire-button at the same time. This should be solved with the above example.

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 xToxicInferno · Feb 18, 2010 at 02:47 AM 0
Share

As usual it works perfectly, as usual! I also created a new weapon so it is 1,2,3. I guess i should say firing mode rather then weapon...either way thanks for the help.

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

How to toggle between 3 different settings 5 Answers

How to implement a delay between each time my gun fires (using coroutines or otherwise)?... 2 Answers

problem with Raygun 1 Answer

Mario Kart Style random weapon 3 Answers

Second Camera 0 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