Search Unity

Top down shooter weapon pickup problems.

Discussion in 'Scripting' started by DesertOps, May 10, 2017.

  1. DesertOps

    DesertOps

    Joined:
    May 4, 2017
    Posts:
    15
    So, I have posted here before and I appreciate the help I got but it didn't quite solve my problem. The problem is, whenever my character goes to a weapon he is supposed to pick it up if I press the right mouse button but he doesn't. I have a weapon pick up script, a box collider 2d set as a trigger and a rigidbody 2d on the pickups. I also have a rigidbody 2d on the player but I don't know if I need to add a box collider to him or not. I am not that good at explaining this problem as I am not an experienced programmer so I will give you links to the weapon attack and weapon pickup scripts and I will include a download link to my project files in case you want to see the problem with your own eyes. I'm not getting any errors, it just seems like the weapon pickup script is not working or something. And also, the game is a Hotline Miami inspired top down shooter. I am using the sprites from the game as place holders until I can find or make other ones. Just felt like I had to mention that, anyways here are the links.
    Weapon attack script: https://pastebin.com/uS2bLS2R
    Weapon pickup script: https://pastebin.com/MvTnEqiV
    Project files: http://www.mediafire.com/file/28wbnr6n8h496cm/Project_files.rar
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    Add a 2D box collider to your player and then change OnTriggerEnter2D to OnTriggerStay2D in WeaponPick.cs
     
  3. DesertOps

    DesertOps

    Joined:
    May 4, 2017
    Posts:
    15
    Should the box collider on the player be a trigger as well or no?
     
  4. DesertOps

    DesertOps

    Joined:
    May 4, 2017
    Posts:
    15
    Ok, forget what I said. I did it and now it works! The player picks up weapons, the sprites change to the player holding the weapon but the legs of the player are disconnected from the body when attacking. Is there anyway I cam make the legs stick to the sprite whenever it changes?
     
  5. douglas09YT

    douglas09YT

    Joined:
    Jan 17, 2022
    Posts:
    1
    hey, i'm making a game, does this works with floating guns?