Esempio n. 1
0
    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();
        }
    }
Esempio n. 2
0
    public override void Hit(RaycastHit hit, SVBullet bullet, Vector3 rayDirection)
    {
        base.Hit(hit, bullet, rayDirection);

        if (!isRotating)
        {
            StartCoroutine(AnimateTargetTo(this.transform.localRotation * upRotation));
        }
    }
Esempio n. 3
0
    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;
    }