void Fire() { if (weaponData == null) { Debug.LogError("Did not find any WeaponData in our children!"); return; } if (weaponData.GetCooldown()) { Debug.Log("cooldown active.."); return; } if (weaponData.GetReloading()) { Debug.Log("on reload.."); return; } if (weaponData.magazines != -1) { if (weaponData.magazines == 0 && weaponData.GetBullets() <= 0) { Debug.Log("no more magazines.."); return; } } weaponData.Shoot(); Debug.Log("Firing!"); Ray ray; Transform hitTransform; Vector3 hitPoint; if (weaponData.shooting == true) { //shooting ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); hitTransform = FindClosestHitObject(ray, out hitPoint); if (hitTransform != null) { Debug.Log("We hit: " + hitTransform.name); // We could do a special effect at the hit location // DoRicochetEffectAt( hitPoint ); Health h = hitTransform.GetComponent <Health>(); while (h == null && hitTransform.parent) { hitTransform = hitTransform.parent; h = hitTransform.GetComponent <Health>(); } // Once we reach here, hitTransform may not be the hitTransform we started with! if (h != null) { // This next line is the equivalent of calling: // h.TakeDamage( damage ); // Except more "networky" PhotonView pv = h.GetComponent <PhotonView>(); if (pv == null) { Debug.LogError("Freak out!"); } else { TeamMember tm = hitTransform.GetComponent <TeamMember>(); TeamMember myTm = this.GetComponent <TeamMember>(); if (tm == null || tm.teamID == 0 || myTm == null || myTm.teamID == 0 || tm.teamID != myTm.teamID) { //We hit an enemy -> give him damage h.GetComponent <PhotonView>().RPC("TakeDamage", PhotonTargets.AllBuffered, weaponData.damage); //set timer to 0.1 sec timerHitmarker = 0.1f; } } } if (fxManager != null) { DoGunFX(hitPoint); } } else { // We didn't hit anything (except empty space), but let's do a visual FX (& Audio) anyway if (fxManager != null) { hitPoint = Camera.main.transform.position + (Camera.main.transform.forward * 1000f); DoGunFX(hitPoint); } } } else { //knifing - same, but other FX ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); hitTransform = FindClosestHitObject(ray, out hitPoint); if (hitTransform != null && Vector3.Distance(ray.origin, hitPoint) <= 2) { Debug.Log("We hit: " + hitTransform.name); // We could do a special effect at the hit location // DoRicochetEffectAt( hitPoint ); Health h = hitTransform.GetComponent <Health>(); while (h == null && hitTransform.parent) { hitTransform = hitTransform.parent; h = hitTransform.GetComponent <Health>(); } // Once we reach here, hitTransform may not be the hitTransform we started with! if (h != null) { // This next line is the equivalent of calling: // h.TakeDamage( damage ); // Except more "networky" PhotonView pv = h.GetComponent <PhotonView>(); if (pv == null) { Debug.LogError("Freak out!"); } else { TeamMember tm = hitTransform.GetComponent <TeamMember>(); TeamMember myTm = this.GetComponent <TeamMember>(); if (tm == null || tm.teamID == 0 || myTm == null || myTm.teamID == 0 || tm.teamID != myTm.teamID) { //We hit an enemy -> give him damage h.GetComponent <PhotonView>().RPC("TakeDamage", PhotonTargets.AllBuffered, weaponData.damage); //set timer to 0.1 sec timerHitmarker = 0.1f; } } } if (fxManager != null) { DoKnifeFX(hitPoint); } } else { //didn't hit anything in our range } } }
private void InitWeapon(WeaponData data) { SetCooldown (data.GetCooldown()); //Debug.Log (cooldown); }