/// <summary> /// NETWORKED FUNCTION: FireBullet /// </summary> /// <param name="value"></param> /// <param name="hitPoint"></param> /// <param name="hitTarget"></param> /// <param name="ownerName"></param> public void FireBulletFX(bool value, Vector3 hitPoint, HitTargets hitTarget, string ownerName) { doBulletFX = value; receivedHitPoint = hitPoint; receivedHitTarget = hitTarget; receivedOwnerName = ownerName; }
/// <summary> /// FIXED UPDATE CALL /// </summary> /// <param name="ray"></param> /// <param name="hitPoint"></param> /// <returns></returns> private Transform FindClosestHitObject_FixedUpdate(Ray ray, out Vector3 hitPoint) { hits = Physics.RaycastAll(ray, 2000f, nonItemLayerMask); closestHit = null; float distance = 0; hitPoint = Vector3.zero; bool foundHit = false; foreach (RaycastHit hit in hits) { currentHitTransform = hit.transform; currentHit = hit; if (currentHitTransform != transform && (closestHit == null || hit.distance < distance)) { //we have hit something that is: //a) not us //b) the first thing we hit (that is not us) //c) or, if not b, is at least closer than the previous closest thing foundHit = true; closestHit = currentHitTransform; distance = hit.distance; hitPoint = hit.point; } } //closestHit is now either still null (i.e. we hit nothing) OR it contains the closest thing that is valid to hit if (closestHit == null) { hitPoint = playerCamera.position + (playerCamera.forward * 2000f); hitTarget = HitTargets.Nothing; } else { if (closestHit.CompareTag("Player")) { hitTarget = HitTargets.Player; } else if (closestHit.CompareTag("Level")) { hitTarget = HitTargets.Environment; } else { hitTarget = HitTargets.Environment; } } return(closestHit); }
/// <summary> /// NETWORK EVENT CALLS: Network FireBullet /// </summary> /// <param name="value"></param> /// <param name="hitPoint"></param> /// <param name="hitTarget"></param> /// <param name="ownerName"></param> public void FireBulletFX_Event(bool value, Vector3 hitPoint, HitTargets hitTarget, string ownerName) { object[] datas = new object[] { value, hitPoint, hitTarget, ownerName }; if (PhotonNetwork.offlineMode) { FireBulletFX(value, hitPoint, hitTarget, ownerName); } else { RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.DoNotCache, Receivers = ReceiverGroup.Others }; PhotonNetwork.RaiseEvent((byte)PhotonEventCodes.FireBulletFX, datas, false, options); } }