public virtual void Hit(RaycastHit hit, SVBullet bullet, Vector3 rayDirection) { if (audioSource == null) { if (!GetComponent <AudioSource> ()) { audioSource = gameObject.AddComponent <AudioSource> (); } else { audioSource = GetComponent <AudioSource> (); } audioSource.clip = bulletHitSoundEffect; } if (GetComponent <Rigidbody> ()) { Rigidbody rb = GetComponent <Rigidbody> (); Vector3 impactForce = bullet.bulletMass * Mathf.Pow(bullet.bulletVelocity, 2) * rayDirection; rb.AddForceAtPosition(impactForce, hit.point); } if (bulletHitSoundEffect != null) { audioSource.pitch = Random.Range(minPitch, maxPitch); audioSource.volume = volume; audioSource.Play(); } }
public override void Hit(RaycastHit hit, SVBullet bullet, Vector3 rayDirection) { base.Hit(hit, bullet, rayDirection); if (!isRotating) { StartCoroutine(AnimateTargetTo(this.transform.localRotation * upRotation)); } }
public void Fire() { GameObject muzzleFlash = Instantiate(muzzleFlashPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation); muzzleFlash.transform.localScale = this.gameObject.transform.lossyScale; GameObject bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation); SVBullet bulletScript = bullet.GetComponent <SVBullet> (); bulletScript.bulletVelocity = muzzleVelocity; bulletScript.hitLayers = hitLayers; bullet.transform.localScale = this.gameObject.transform.lossyScale; }