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 thenickhis · Aug 02, 2012 at 09:03 PM · gameobjectchildactivateequipsetactiverecursively

Activating gameObject issue...

I have a gameobject called weaponPrimary and one called weaponSecondary, so the player can have one out or both out at the same time. All the possible weapons are childed under both of them, having only one active according to the player's choice on the loadout menu. By pressing 1, weaponPrimary either activates or deactivates, and same for weaponSecondary with pressing 2. weaponPrimary/Secondary have a weaponmanager script that keeps track of which child should be active by assigning the child to the "equipped" variable. This is all working fine except for one thing: Whenever weaponPrimary/Secondary reactivates, ALL the children reactivate with it for a split-second and then disappear, leaving the equipped weapon active. This looks bad, as a large mass of weapons flicker on and off every time. I use SetActiveRecursively for deactivate for switching weaponPrimary/Secondary and weapons off, but I only reactivate the weaponPrimary/Secondary and the child that is set as equipped. Any help on this would be appreciated.

Here is the previously mentioned weaponmanager script on weaponPrimary/Secondary: var rifle : Transform; var pistol : Transform; var armlaser : Transform; var armemp : Transform; var equipped : Transform;

 function Update () {
  if (rifle == equipped) {
  rifle.gameObject.SetActiveRecursively(true);
  } else
  {
  rifle.gameObject.SetActiveRecursively(false);
  }
  if (pistol == equipped) {
  pistol.gameObject.SetActiveRecursively(true);
  } else
  {
  pistol.gameObject.SetActiveRecursively(false);
  }
  if (armlaser == equipped) {
  armlaser.gameObject.SetActiveRecursively(true);
  } else
  {
  armlaser.gameObject.SetActiveRecursively(false);
  }
  if (armemp == equipped) {
  armemp.gameObject.SetActiveRecursively(true);
  } else
  {
  armemp.gameObject.SetActiveRecursively(false);
  }
 }

and here is the excerpt of the script that determines the button pressing:

  if (primaryout)
         {
         primaryWeapon.gameObject.active = true;
         primaryWeapon.gameObject.GetComponent("weaponmanager").equipped.gameObject.SetActiveRecursively(true);
         } else
         {
         primaryWeapon.gameObject.SetActiveRecursively(false);
         }
         
         if (Input.GetButtonDown("Draw primary weapon"))
         {
          if (primaryout)
          {
          primaryout = false;
          alreadyCheckedprimary = true;
          }
          if (!primaryout && !alreadyCheckedprimary)
          {
          primaryout = true;
          }
         }
         
         if (secondaryout)
         {
         secondaryWeapon.gameObject.active = true;
         secondaryWeapon.gameObject.GetComponent("weaponmanager").equipped.gameObject.SetActiveRecursively(true);
         } else
         {
         secondaryWeapon.gameObject.SetActiveRecursively(false);
         }
         
         if (Input.GetButtonDown("Draw secondary weapon"))
         {
          if (secondaryout)
          {
          secondaryout = false;
          alreadyCheckedsecondary = true;
          }
          if (!secondaryout && !alreadyCheckedsecondary)
          {
          secondaryout = true;
          }
         }
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 fafase · Aug 02, 2012 at 09:19 PM 0
Share

You should post your code. There is no way for us to find out what is wrong just by telling us even though you give a lot of details.

Your solution in the meanwhile could be to have an animation that hides the weapon and then switch it. When changing the animation takes the weapon out of camera view and comes back with a different weapon.

avatar image thenickhis · Aug 02, 2012 at 09:53 PM 0
Share

Thanks for the comment, that would work if there wasn't other players in the game. I updated my question with the scripts.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Sundar · Aug 02, 2012 at 10:25 PM

Set all meshRenderer of children false and show only the ones that need to be seen.

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 thenickhis · Aug 02, 2012 at 11:04 PM 0
Share

Thank you! I have to overhaul my script, but it seems to be working better this way.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot deactivate / activate gameobject, even in editor! 6 Answers

Very Erratic behavior when parenting an object 0 Answers

change pivot of parent game object 1 Answer

Finding Children question 3 Answers

How to activate the child of an object without declaring a public transform? 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