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 · Sep 13, 2013 at 05:32 PM · animationweaponweaponchanging

Using weapon switching script makes any weapons with animations disappear

EDIT: Have discovered that if I remove the animation from my sword, it appears. What good is that though, having a weapon I can't use, unless this is jousting?

Ok, so my original question asked about getting a weapon switching script working, which I've now done, praise God! =) There's a strange issue now though, and thought I'd throw it out to the community. If I follow exactly as the tutorial here shows, add the script (below), parent script to main camera, child an empty object to the main camera (a weapon manager, so to speak) and child a cube (weapon) and sphere (another weapon) to that manager, everything goes swimmingly, I can switch between the cube and sphere. Yay! Accept, nobody wants to carry a cube or sphere around as a weapon. No problem, right? That's just proof of concept. I'll just add my sword on there, which I've been using with no issues for the longest... wait, dude, where's my sword? It's like, not there! I mean, I did check to make sure there were slots for three weapons, and nothing. Cube and sphere are there just fine, but my sword (a 3d model) doesn't appear. Once again, any help or advice is humbly accepted and appreciated. God bless.

 function Start () {
     // Select the first weapon
     SelectWeapon(0);
 }
 
 function Update () {
     // Did the user press fire?
     if (Input.GetButton ("Fire1"))
         BroadcastMessage("Fire");
     
     if (Input.GetKeyDown("1")) {
         SelectWeapon(0);
     }    
     else if (Input.GetKeyDown("2")) {
     SelectWeapon(1);
     }
     else if (Input.GetKeyDown("3")) {
     SelectWeapon(2);
     }
     }
     
     
     
 
 function SelectWeapon (index : int) {
     for (var i=0;i<transform.childCount;i++)    {
         // Activate the selected weapon
         if (i == index)
             transform.GetChild(i).gameObject.SetActiveRecursively(true);
         // Deactivate all other weapons
         else
             transform.GetChild(i).gameObject.SetActiveRecursively(false);
     }
 }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by YoungDeveloper · Sep 13, 2013 at 05:57 PM

Instead of finding child (weapon) in for loop, I'd suggest creating an GameObject or whatever array for weapons, lets say size of 5 (5 weapons slots). Then set each object in he inspector, to access that object you just write the index, array[0]...

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
avatar image
0

Answer by Conect11 · Sep 13, 2013 at 10:34 PM

Wahoo, I love jury - rigged solutions! Ok, the quick and dirty I way I found of fixing this is to attach another game object (say, a cube) into the weapon select game object, position it so that it can't be seen, and then parent the sword (or whatever weapon you want) to that. Then you can have your animation on the weapon (not the new game object) and everything works great. =)

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

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

Mecanim not updating script when it switches state? 2 Answers

weapon animation question 1 Answer

Attaching Weapon to Animated Character 0 Answers

Multiple Weapon Animation Help 0 Answers

can some onehelp me with this code(Js). (No Errors). 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