Пример #1
0
 void OnTriggerEnter(Collider c)
 {
     if (detachableMag && !attachMagazine)
     {
         Magazine tempMagazine = c.GetComponentInParent <Magazine> ();
         if (tempMagazine && tempMagazine.ammoType == ammoType)
         {
             //игнор колайтеров магазина
             myCollidersToIgnore = GetComponentInParent <PrimitiveWeapon> ().gameObject.GetComponentsInChildren <Collider> ();
             for (int j = 0; j < myCollidersToIgnore.Length; j++)
             {
                 for (int k = 0; k < tempMagazine.MagazineColliders.Length; k++)
                 {
                     Physics.IgnoreCollision(myCollidersToIgnore[j], tempMagazine.MagazineColliders[k]);
                 }
             }
             PhysicalObject tempPhysicalObject = tempMagazine.GetComponent <PhysicalObject>();
             if (tempPhysicalObject)
             {
                 tempPhysicalObject.DettachHands();
                 tempPhysicalObject.MyRigidbody.isKinematic = true;
             }
             tempMagazine.transform.parent        = magazineAttachPoint;
             tempMagazine.transform.localPosition = Vector3.zero;
             tempMagazine.transform.localRotation = Quaternion.identity;
             attachMagazine = tempMagazine;
             tempMagazine.primitiveWeapon = this;
             tempMagazine.canLoad         = false;
             MagazineLoad.Invoke();
             return;
         }
     }
 }
Пример #2
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.GetComponent <MagazineController>() && other.GetComponent <PhysicalObject>())
        {
            PhysicalObject     interactionController = other.GetComponent <PhysicalObject>();
            MagazineController magController         = other.GetComponent <MagazineController>();

            if (magController.magType == weaponController.magConfig.type && !weaponController.magConfig.attached && weaponController.magConfig.isDetachable)
            {
                interactionController.DettachHands();
                other.transform.position = weaponController.magConfig.attachPoint.position;
                other.transform.rotation = weaponController.magConfig.attachPoint.rotation;

                other.GetComponent <Rigidbody>().isKinematic = true;
                other.transform.parent              = weaponController.transform;
                magController.weaponController      = weaponController;
                weaponController.attachedMag        = magController;
                weaponController.magConfig.attached = true;
                weaponController.onMagazineAttach.Invoke();
                other.gameObject.layer          = magAttachedLayer;
                magController.stikingAmmo.layer = magAttachedLayer;
            }
        }
    }