public void DoBulletImpactFx(RaycastHit hit) { PhysicMaterial mat = hit.collider.sharedMaterial; audioSrc.transform.position = hit.point; audioSrc.PlayOneShot(BulletImpactSound(mat)); Sound.MakeSound(audioSrc.transform.position, Sound.Type.GUNSHOT, impactSoundLevel, 1); EffectTemporary effect = (EffectTemporary)Instantiate(BulletImpactEffect(mat), hit.point, Quaternion.identity); effect.transform.forward = hit.normal; effect.transform.parent = hit.collider.transform; }
public MaterialFxInstance(MaterialFxSerialize serialized) { this.impactSounds = serialized.impactSounds; this.impactEffect = serialized.impactEffect; }
/** * Shoot the gun */ private bool Shoot() { if (timeSinceLastShot < shotDelay) { return(false); } if (numBulletsLoaded <= 0) { return(false); } // Fire the bullet ray RaycastHit hit = new RaycastHit(); Ray ray = new Ray(aimOriginTransform.position, aimTarget.target - aimOriginTransform.position); if (Physics.Raycast(ray, out hit, maxRange, layers)) { // Spawn muzzle flash particle if (muzzleFlashEffect) { Transform barrel = null; if (viewModel) { barrel = viewModel.points[0]; } else if (worldModel) { barrel = viewModel.points[0]; } if (barrel) { EffectTemporary flash = (EffectTemporary)Instantiate(muzzleFlashEffect, barrel.position, barrel.rotation); flash.transform.parent = aimOriginTransform; flash.transform.forward = aimOriginTransform.forward; } } // Spawn impact particle MaterialFxManager.Instance.DoBulletImpactFx(hit); // Damage object Damageable damageable = hit.collider.GetComponentInChildren <Damageable>(); if (!damageable) { damageable = hit.collider.GetComponentInParent <Damageable>(); } if (damageable) { damageable.Damage(impactDamage, impactForce, hit, ray.direction); } } // Debug - draw the bullet ray if (hit.distance <= 0.01f) { hit.distance = 100f; } Debug.DrawRay(ray.origin, ray.direction.normalized * hit.distance, Color.white, 0.5f); PlayShootSound(); timeSinceLastShot = 0; numBulletsLoaded--; return(true); }