Пример #1
0
    protected void Fire()
    {
        // Play the proper sounds depending on the player's ammo
        if (ammo.HasAmmo(tag))
        {
            GetComponent <AudioSource>().PlayOneShot(liveFire);
            ammo.ConsumeAmmo(tag);

            // Play the fire animation
            GetComponentInChildren <Animator>().Play("Fire");

            // Creates a ray along the camera's viewport with length of the range of the current weapon, checks if it hits anything and if it does, processes the hit
            Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, range))
            {
                processHit(hit.collider.gameObject);
            }
        }
        else
        {
            GetComponent <AudioSource>().PlayOneShot(dryFire);
        }
    }
Пример #2
0
    //method to fire gun
    protected void Fire()
    {
        //check if gun has ammo
        if (ammo.HasAmmo(tag))
        {
            GetComponent <AudioSource>().PlayOneShot(liveFire);
            ammo.ConsumeAmmo(tag);
        }
        else
        {
            GetComponent <AudioSource>().PlayOneShot(dryFire);
        }

        //play gun firing animation
        GetComponentInChildren <Animator>().Play("Fire");
        //chcek if the shot hit
        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, range))
        {
            ProcessHit(hit.collider.gameObject);
        }
        //Debug.DrawRay(transform.parent.position, ray.direction * range, Color.green, 2.0f);
    }
Пример #3
0
    protected void Fire()
    {
        if (ammo.HasAmmo(tag))
        {
            // Debug.Log("ammo " + tag + " = " + ammo.GetAmmo(tag));
            AudioSource source = GetComponent <AudioSource>();

            // GetComponent<AudioSource>().PlayOneShot(liveFire);
            if (!source.isPlaying)
            {
                source.clip = liveFire;
                source.Play();
            }
            else
            {
                // Debug.LogError("ERRORRRR");
            }
            ammo.ConsumeAmmo(tag);
        }
        else
        {
            GetComponent <AudioSource>().PlayOneShot(dryFire);
        }
        GetComponentInChildren <Animator>().Play("Fire");


        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, range))
        {
            ProcessHit(hit.collider.gameObject);
        }
    }
Пример #4
0
 protected void Fire()
 {
     if (ammo.HasAmmo(tag))
     {
         GetComponent <AudioSource>().PlayOneShot(liveFire);
         ammo.ConsumeAmmo(tag);
     }
     else
     {
         GetComponent <AudioSource>().PlayOneShot(dryFire);
     }
     GetComponentInChildren <Animator>().Play("Fire");
 }
Пример #5
0
 protected void Fire()
 {
     // Fetches the animation controller and tells it to play the "Fire"
     // animation. Checks if the player has any remaining ammunition, if so, play
     // the liveFire sound; otherwise, play dryFire sound.
     if (ammo.HasAmmo(tag))
     {
         GetComponent <AudioSource>().PlayOneShot(liveFire);
         ammo.ConsumeAmmo(tag);
     }
     else
     {
         GetComponent <AudioSource>().PlayOneShot(dryFire);
     }
     GetComponentInChildren <Animator>().Play("Fire");
 }
Пример #6
0
    protected void Fire()
    {
        if (ammo.HasAmmo(AmmoEquipper.activeAmmoType))
        {
            GetComponent <AudioSource> ().PlayOneShot(liveFire);
            ammo.ConsumeAmmo(AmmoEquipper.activeAmmoType);

            GameObject bullet = Instantiate(equipper.GetActiveAmmo());
            bullet.transform.position = firePosition.position;
            bullet.transform.rotation = firePosition.rotation;
        }
        else
        {
            GetComponent <AudioSource> ().PlayOneShot(dryFire);
        }

        GetComponentInChildren <Animator> ().Play("Fire");
    }
Пример #7
0
    protected void Fire()
    {
        if (ammo.HasAmmo(tag))
        {
            GetComponent <AudioSource>().PlayOneShot(liveFire); ammo.ConsumeAmmo(tag);
        }
        else
        {
            GetComponent <AudioSource>().PlayOneShot(dryFire);
        }
        GetComponentInChildren <Animator>().Play("Fire");
        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, range))
        {
            processHit(hit.collider.gameObject);
        }
    }
Пример #8
0
    protected void Fire()
    {
        if (ammo.HasAmmo(tag)) // if gun has ammo will play fire sound
        {
            GetComponent <AudioSource>().PlayOneShot(liveFire); ammo.ConsumeAmmo(tag);
        }
        else // if out of ammo will play empty sound
        {
            GetComponent <AudioSource>().PlayOneShot(dryFire);
        }

        GetComponentInChildren <Animator>().Play("Fire"); // looks for the animator controller for pistol and plays fire animation

        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, range))
        {
            processHit(hit.collider.gameObject);
        }
    }