Search Unity

How to spawn weapon to player?

Discussion in 'Getting Started' started by FelixCoffin, Sep 11, 2019 at 7:23 AM.

  1. FelixCoffin

    FelixCoffin

    Joined:
    Nov 6, 2017
    Posts:
    1
    I've got my player moving around and able to be attacked by enemy NPC's and now I'm trying to figure out how to attack them back. I want to make the player spawn a sword that attaches to his hand via action button and perform have a different run animation when equipped. Would I have to make a seperate model where the player is already equipped and have it replace the non equipped model or is there a way to have the sword just appear?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,130
    I will wildly guess (since you haven't told us) that your player is a 3D model with a SkinnedMeshRenderer, animated via a skeleton that consists of a hierarchy of mostly empty GameObjects.

    In that case, you just need to find the GameObject that represents the hand, and put the sort model there. Deactivate it so that it is normally invisible. Then, when it's time to fight, simply activate it. The sword is there all the time, and moves properly with the model animations, but you only show it when you want to.