shadowx320

WeaponSlotManager

Apr 8th, 2021
367
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace SG
  6. {
  7.     public class WeaponSlotManager : MonoBehaviour
  8.     {
  9.         WeaponHolderSlot leftHandSlot;
  10.         WeaponHolderSlot rightHandSlot;
  11.  
  12.         DamageCollider leftHandDamageCollider;
  13.         DamageCollider rightHandDamageCollider;
  14.  
  15.         private void Awake()
  16.         {
  17.             WeaponHolderSlot[] weaponHolderSlots = GetComponentsInChildren<WeaponHolderSlot>();
  18.             foreach (WeaponHolderSlot weaponSlot in weaponHolderSlots)
  19.             {
  20.                 if (weaponSlot.isLeftHandSlot)
  21.                 {
  22.                     leftHandSlot = weaponSlot;
  23.                 }
  24.                 else if (weaponSlot.isRightHandSlot)
  25.                 {
  26.                     rightHandSlot = weaponSlot;
  27.                 }
  28.             }
  29.         }
  30.  
  31.         public void LoadWeaponOnSlot(WeaponItem weaponItem, bool isLeft)
  32.         {
  33.             if (isLeft)
  34.             {
  35.                 leftHandSlot.LoadWeaponModel(weaponItem);
  36.                 LoadLeftWeaponDamageCollider();
  37.             }
  38.             else
  39.             {
  40.                 rightHandSlot.LoadWeaponModel(weaponItem);
  41.                 LoadRightWeaponDamageCollider();
  42.             }
  43.         }
  44.  
  45.         #region Handle Weapon's Damage Collider
  46.  
  47.         private void LoadLeftWeaponDamageCollider()
  48.         {
  49.             leftHandDamageCollider = leftHandSlot.currentWeaponModel.GetComponentInChildren<DamageCollider>();
  50.         }
  51.  
  52.         private void LoadRightWeaponDamageCollider()
  53.         {
  54.             rightHandDamageCollider = rightHandSlot.currentWeaponModel.GetComponentInChildren<DamageCollider>();
  55.         }
  56.  
  57.         public void OpenRightDamageCollider()
  58.         {
  59.             rightHandDamageCollider.EnableDamageCollider();
  60.         }
  61.  
  62.         public void OpenLeftDamageCollider()
  63.         {
  64.             leftHandDamageCollider.EnableDamageCollider();
  65.         }
  66.  
  67.         public void CloseRightDamageCollider()
  68.         {
  69.             rightHandDamageCollider.DisableDamageCollider();
  70.         }
  71.  
  72.         public void CloseLeftDamageCollider()
  73.         {
  74.             leftHandDamageCollider.DisableDamageCollider();
  75.         }
  76.  
  77.         #endregion
  78.     }
  79. }
  80.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×