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; } } }
public override void InsertMagazine(Magazine magazine) { if ((Magazine)FindPartByType("Magazine") != null) return; magazine.GetComponent<Rigidbody>().isKinematic = true; Attach(magazine, body); if (ammoCounter) ammoCounter.Refill(); }
public void CheckAmunition() { if (!hasMagazine && !isLinearDriving) { Collider[] mags = Physics.OverlapSphere(magazinePostition.position, checkMagazineRadious, magazineLayer); foreach (var mag in mags) { float distance = Vector3.Distance(magazinePostition.position, mag.transform.position); Magazine magazine = mag.GetComponentInParent <Magazine>(); if (!isLinearDriving) { if (lastMag == magazine) { if (distance > startMagazineLinearDrive) { lastMag = null; } } } if (timeBeforeReload >= 0) { // lastMag = null; } if (distance < startMagazineLinearDrive) { if (lastMag != magazine) { float angle = Quaternion.Angle(magazinePostition.rotation, magazine.transform.rotation); //Debug.Log(angle); if (angle <= attachAngle) { lastMag = magazine; if (magazine.GetComponent <Interactable>().attachedToHand == null || !isLinearDrive) { AttachMagazine(magazine); return; } else { StartLinearDrive(magazine); return; } } } } } } }
public void StartLinearDrive(Magazine magazine) { MyLinearDrive ld = magazine.GetComponent <MyLinearDrive>(); if (ld != null) { isLinearDriving = true; //Physics.IgnoreCollision(GetComponentInChildren<Collider>(), magazine.GetComponentInChildren<Collider>(), true); ld.startPosition = startMagazineLinearDrivePosition; ld.endPosition = endMagazineLinearDrivePosition; ld.startingRotation = magazinePostition.rotation; ld.OnActivated(GetComponentInChildren <LinearMapping>(), this); } else { DisAttachMagazine(); } }