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
0
Question by nhftk12 · May 31, 2011 at 12:30 PM · animationswitchswordswitch objects

Swtich weapons problem (attach to bone)

I made a sword that need to be pull when I switching weapons. I used for that a code that attach the sword to the bone in the hand when a variable in the character's code is true. The problem is that the sword is always attached to the body's bone and never change it (the sword should been attach to the body's bone when I use another weapon, when I use the sword it should been attach to the hand's bone). Is there any way to make the code works or there is a better way to pull out the swrod?

This is my code:

 var target : Transform; 
  
  function Awake()
  {
      if (BobC.putSword)
      {
          target = GameObject.FindWithTag("Hand").transform;
          transform.parent = target.transform;
      }
      
      if (!BobC.putSword)
      {
          target = GameObject.FindWithTag("Body").transform;
          transform.parent = target.transform;
      }
  }

The code should work when in the withing animation. The sword have no rigidbody and no collider.

Sorry for poor english.

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 Owen-Reynolds · May 31, 2011 at 07:25 PM 0
Share

Awake only runs once. Does putSword always start false? To see if the Hand code works, try running just the two lines target=..."Hand" .... If she starts with it in her hand, the problem isn't there.

avatar image RetepTrun · Jun 01, 2011 at 01:43 AM 0
Share

Ins$$anonymous$$d of "if (!BobC.putSword)" I would just say "else"

You could look into "animation event" which I think will execute things based on how far along an animation is.

Or just have a whole bone just for the sword, that way when you draw it the sword will never be actually attached to the hand or body at all. This will even make it possible to do more fancy moves like maybe throw sword in the air and catch it with another hand

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by nhftk12 · Jun 01, 2011 at 06:24 AM

I solved the problem by myself (thnx to Owen Reynolds who sade "Awake only runs once"). I made 2 swords: one attached to the hand and other to the body. With the fact that Awake runs only once I edited the code a bit and attached the code to every part of both swords and every sword attached to another bone from the beginning. in the code I just enabled and disable the renderer every time the variable is true of false (when the sword is been pull out the renderer is visible and when it pull in it not visible).

This is the body's sword code:

 var target : Transform; 
  
  function Awake ()
  {
      target = GameObject.FindWithTag("Body").transform;
      transform.parent = target.transform;
  }
  
  function Update ()
  {
      if (BobC.putSword)
      {
          renderer.enabled = false;
      }
      else
      {
          renderer.enabled = true;
      }
  }

The hand's sword have a similar code to the body's sword but it attached to the hand and not the body and the renderer is visible when the other sword is not visible so it seems like I pull the sword and the sword is not just disappear.

Sorry for poor english.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Programming a Sword Swing Animation and Swapping weapons 1 Answer

Coroutine / Switch case 1 Answer

switch > door animation 0 Answers

Is there any hotkey to swich to the next/previous frame in the animation windows? 2 Answers

How do I have my animated character have a weapon switching system? 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