Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

(Script) Weapon Control Script: v1_1 Aug-8-2010

Discussion in 'Scripting' started by ForceX, Aug 5, 2010.

  1. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    Weapon Control v1_1

    What is Weapon Control Script?
    Weapon Control Script or WCS, is a set of scripts that allows you to easily create any type of projectile based weapon by setting only a few properties in the Inspector.

    How to use Weapon Control Script?
    WCS contains three scripts that work togeather to create your projectile based weapons.

    1. WCS_Master : Place this script on to a gameObject named Player. Create an empty gameObject named WeaponSlot1 and make it a child of Player. WeaponSlot1 will be the spawn point for the projectile prefab.
    Inspector Properties:
    a. Weapon Slot 1 (Place your projectile prefabs here)

    2. WCS_Projectile_Properties: Place this script on to your prefab gameObject that you wish to be your projectile. Give your prefab gameObject a rigidbody component. Then apply your projectile prefab to the Player gameObject in the Inspector into WeaponSlot1.
    Inspector Properties:
    a. Damage (needs a detection system: not in this script)
    b. Rate Of Fire
    c. Spread
    d. Projectile Speed
    e. Projectile Range
    f. Collision Hit Effect

    3. WCS_HitEffect: Place this script on to a prefab gameObject that you wish to use as the effect for your projectile collision hit effect. Then apply your HitEffect prefab to your projectile prefab.
    Inspector Properties:
    a. Hit Effect Life Seconds (How long the effect will last)


    To use Weapon Damage the object that is being shot at needs a" function ApplyDamage(Damage) " this function will of course reference to your HP.

    Implemented features:

    1. Custom Rate Of Fire (set in prefab)
    2. Custom Projectile Speed (Set in prefab)
    3. Custom Projectile Range (Set in prefab)
    4. Custom shooting spread amout (Set in the prefab)
    5. Collision hit detection
    6. Collision hit effect support
    7. Custom Damage (set in prefab)

    Future:

    Change Log:
    v1_1: Aug-8-2010
    a. Improved weapon spread
    b. Added damage

    v1_0: Aug-6-2010
    a. Added projectile spread
    b. Added collision hit detection
    c. Added collision hit effect support
     

    Attached Files:

  2. Xsnip3rX

    Xsnip3rX

    Joined:
    Aug 29, 2009
    Posts:
    197
    should make beams now ;)
     
  3. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    Thats a good idea. Perhaps this weekend after i finish this script. Just working on shot scatter now.
     
  4. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    WCS 1_0 released.

    New features:
    a. Added custom projectile spread
    b. Added collision hit detection
    c. Added collision hit effect support
     
  5. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    WCS v1_1 Released.

    New/Updated Features:
    a. Improved weapon spread
    b. Added damage


    Weapon Spread:
    Before the origin that the projectile was originated at was the point of origin + a random vector x,y. What this did was move the spawn origin around the origin point and the projectiles fired off in a strait trajectory along different z paths relative to the player.

    The new weapon spread apply's a random rotation from the starting origin allowing the projectiles to be generated at the same origin but have different trajectory along there own z.

    In short it's now like a SMG shot spread. This can of course be edited to your likings with in the prefab in the Inspector.

    Damage:
    To use Weapon Damage the object that is being shot at needs a" function ApplyDamage(Damage) " this function will of course reference to your HP.


    example would be:

    Code (csharp):
    1. var Life : int = 100;
    2.  
    3. function ApplyDamage(Damage){
    4.  
    5. Life -= Damage;
    6. }
     
  6. MrRudak

    MrRudak

    Joined:
    Oct 17, 2010
    Posts:
    159
    cool men thanks
     
  7. Mason Cook

    Mason Cook

    Joined:
    Nov 4, 2010
    Posts:
    1
    Just used it, works great fast and easy. Nice work and thanks! :p
     
  8. arvzg

    arvzg

    Joined:
    Jun 28, 2009
    Posts:
    619
    Excellent, I'm working on a game that would really benefit greatly from this. Just downloaded it, will test it out when I get home!
     
  9. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650