Пример #1
0
    void Start()
    {
        Rigidbody rb = GetComponent <Rigidbody>();

        r = rb;
        if (rb)
        {
            rb.velocity = transform.forward * speed;
        }
        dmg   = BootlegRandom.NextRange(minDamage, maxDamage);
        timer = lifetime;
    }
Пример #2
0
 public void Shoot() {
     if (timeLeft > 0 || !isReady) return;
     if (!infiniteAmmo) {
         if (ammo <= 0) {Reload();return;}
         ammo--;
         p.ammoText.text = ammo + "";
         if (ammoDisplay.Length > 0) UpdateAmmoDisplay();
     }
     timeLeft = 1 / fireRate;
     rTime = recoilTime;
     h = 0.1f;
     sTime = 0.1f;
     if (muzzleFlash) Instantiate(muzzleFlash, muzzleFlashSpawn.position, transform.rotation);
     for (var i = 0; i < shots; i++) {
         Vector3 dir = p.cam.forward + new Vector3(BootlegRandom.NextRange(-inaccuracy, inaccuracy), Random.Range(-inaccuracy, inaccuracy), Random.Range(-inaccuracy, inaccuracy));
         if (!projectile) {
             int _i = Mathf.Clamp(i, 0, bulletTrails.Length - 1);
             RaycastHit hit;
             if (Physics.Raycast(p.cam.position, dir, out hit, distance)) {
                 Health h = hit.collider.GetComponent<Health>();
                 Rigidbody rb = hit.collider.GetComponent<Rigidbody>();
                 if (rb) {
                     rb.AddForce(-hit.normal * BootlegRandom.NextRange(minKnockback, maxKnockback), ForceMode.Impulse);
                 }
                 if (h) {
                     h.TakeDamage(BootlegRandom.NextRange(minDamage, maxDamage));
                 }
                 if (hitEffect) {
                     Instantiate(hitEffect, hit.point, Quaternion.identity).transform.forward = hit.normal;
                 }
                 if (bulletTrails[_i]) {
                     bulletTrails[_i].transform.forward = hit.point - muzzleFlashSpawn.position;
                     bulletTrails[_i].transform.position = muzzleFlashSpawn.position;
                     bulletTrails[_i].transform.localScale = new Vector3(1, 1, Vector3.Distance(muzzleFlashSpawn.position, hit.point));
                 }
             } else {
                 if (bulletTrails[_i]) {
                     bulletTrails[_i].transform.forward = dir;
                     bulletTrails[_i].transform.position = muzzleFlashSpawn.position;
                     bulletTrails[_i].transform.localScale = new Vector3(1, 1, distance);
                 }
             }
         } else {
             GameObject pr = Instantiate(projectile, p.cam.position, p.cam.rotation);
             Physics.IgnoreCollision(p.GetComponent<Collider>(), pr.GetComponent<Collider>());
         }
     }
 }