예제 #1
0
파일: Weapon.cs 프로젝트: Alan-Baylis/11
    public void Shoot()
    {
        if (timer >= timeBetweenBullets && weaponBehavior.CanIShoot())
        {
            if (unitAmmoCount > 0)
            {
                unitAmmoCount--;

                timer       = 0f;
                reloadTimer = 0;

                // Enable gunLine, gunLight and Play gunAudio.
                PlayEffects();
            }
            else if (reloadTimer >= timerBetweenReload)
            {
                Reloading();
            }
        }
    }
예제 #2
0
    public void Shoot()
    {
        if (timer >= timeBetweenBullets && weaponBehavior.CanIShoot())
        {
            if (unitAmmoCount > 0)
            {
                unitAmmoCount--;

                timer       = 0f;
                reloadTimer = 0;

                // Enable gunLine, gunLight and Play gunAudio.
                PlayEffects();

                gunLine.SetPosition(0, shotOutPoint.transform.position);

                // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
                shootRay.origin    = shotOutPoint.transform.position;
                shootRay.direction = shotOutPoint.transform.forward;

                // Perform the raycast against gameobjects on the shootable layer and if it hits something...
                if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
                {
                    Hero hero = shootHit.collider.GetComponent <Hero> ();
                    hero.TakeDemage();
                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
                }
            }
            else if (reloadTimer >= timerBetweenReload)
            {
                Reloading();
            }
        }
    }