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 Conect11 · Oct 18, 2013 at 03:18 AM · cycleweaponchanging

Trying to cycle through weapons

So after days of pounding my head into my keyboard, and with a lot of help from Miziziziz and Griffo I finally was blessed to get the weapon switch script I was using to work nearly flawlessly. Now the player won't have a weapon until they actually pick it up. Sounds simple, but I was amazed how involved the process was. Thanks to everyone who helped! There's a small issue at the tail end now, that I'm hoping is easy to fix and that I'm just missing: The weapons properly cycle once through each of the gameobjects. (empty hand, club, sword, and then back to empty hand.) But then from the second cycle weapon 2 is always skipped (club) so that it now goes empty hand, sword, empty hand. Am hoping someone might point out what I'm doing wrong. Thanks, and God bless.

  var Weapon01 : GameObject; // empty hand
     var Weapon02 : GameObject; // club
     var Weapon03 : GameObject; //sword
     static var weaponready = false;
     static var swordready = false;
      
      
      
     function Update () {
      
     if (Input.GetButtonDown("Weapon Switch")) {
     if (weaponready == true)
     SelectWeapon();
     }
     }
      
      
      
      
      
     function SelectWeapon () {
     if (Weapon01.active == true)
      
     {
     if (WeaponInv.Club >=1)
     Weapon01.SetActiveRecursively(false);
     Weapon02.SetActiveRecursively(true);
     Weapon03.SetActiveRecursively(false);
     }
     if (Input.GetButtonDown("Weapon Switch")) {
     if (WeaponInv.Sword >=1)
     if (swordready == true)
     SwordSelect();
     }
     }
      
     function SwordSelect () {
     if (Weapon02.active == true)
     {
     if (WeaponInv.Sword >=1)
     if (swordready == true)
     Weapon01.SetActiveRecursively(false);
     Weapon02.SetActiveRecursively(false);
     Weapon03.SetActiveRecursively(true);
     }
      
     else
     {
     if (Weapon03.active == true)
      
     {
     Weapon01.SetActiveRecursively(true);
     Weapon02.SetActiveRecursively(false);
     Weapon03.SetActiveRecursively(false);
     }
      
     }
      
     } 
Comment
Add comment · Show 2
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 Spider_newgent · Oct 18, 2013 at 08:16 AM 0
Share

I'm presu$$anonymous$$g you're starting off with the empty hand, and can pick up objects in any order, so that weapon 2 could either be the club or the sword? If that's the case, does the problem occur irrespective of which weapon is in slot 2?

And are you printing the active weapon to the debug.log?

avatar image Conect11 · Oct 18, 2013 at 12:23 PM 0
Share

haven't used the debug.log yet. You are correct as to being able to pick up the weapons in any order, but their placement is static. Slot 1 is always listed as empty, 2 as club, 3 as sword. No matter what order they're picked up in, as soon as the sword is equipped the first time the club can never be equipped again. It goes from the desired order of empty - club - sword to empty - sword. Something in the script is making the cycle skip the club entirely.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pecek · Oct 18, 2013 at 11:09 AM

You could just create an array of game objects(the weapons), and cycle through the elements of it(when the player scrolls up or something), that way you can add more weapons later without pain, and the code would look a lot more cleaner.

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 Conect11 · Oct 18, 2013 at 12:24 PM 0
Share

thanks Peck. I walked away from arrays last week when I found it was a major pain to save them (and their items) into PlayerPrefs, so I was hoping to avoid them, if possible =(

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

16 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

Related Questions

[SOLVED] Cycling all the way through weapons properly 1 Answer

Using weapon switching script makes any weapons with animations disappear 2 Answers

Audio Score Trigger Help 0 Answers

I can't get my script to work I get an error. [Please Help!] 0 Answers

Activating Bool Array in sequence. 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