Search Unity

2D weapon system

Discussion in 'Scripting' started by aidanseeberg, May 31, 2016.

  1. aidanseeberg

    aidanseeberg

    Joined:
    Jul 10, 2015
    Posts:
    26
    Hi,
    I am creating a game in which you have three weapons at once, a melee(that you start with at the beginning of the game), gunA, and gunB (both guns are picked up during the course of the game). The guns are customizable in the sense that there are multiple weapons. (shotgun, ak-47, m9, uzi). Gun A and Gun B are not on a primary/secondary basis. My question is how do I make a system in which you can choose the gun you use and how do I swap between the two traits of the guns (ex. fire rate, dmg, and ammo capacity). A response would be greatly appreciated. Thank you
     
  2. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    You can write a new class for WeaponType maybe, and then:
    WeaponType gunA, gunB;

    Somewhere you'd have a list or array of possible weapon types, created when game starts.
     
  3. mumbot

    mumbot

    Joined:
    Oct 19, 2012
    Posts:
    86
    There are many ways to go about weapon switching. A simple way could be for you to pre set the gameobject position on the player but then set it to active when an event is triggered this event could be on pickup using the OnCollisionEnter function or when a key is pressed using Input.getkey.