コード例 #1
0
        public override bool Fire(Vector3 position, Vector3 direction, float range, int ignoreLayer)
        {
            bool returnValue = false;

            CurrentShootInverval += Time.deltaTime;
            RaycastHit hit;

            // Fire towards player
            if (CurrentShootInverval > ShootRate && Physics.Raycast(position, direction, out hit, range, ignoreLayer))
            {
                sniperFireSound.Play();
                if (hit.collider.tag == "PlayerOne")
                {
                    Debug.Log("Player one shot");
                    if (PlayerOneHealth.DeductHP(Damage))
                    {
                        returnValue = true;
                    }
                    else
                    {
                        playerOneSlow.ApplyGeneralSlow(0.0f, 8.0f, 0.1f, speedPenalty);
                        HitFlash.FlashCamera(1);
                    }
                }
                else if (hit.collider.tag == "PlayerTwo")
                {
                    Debug.Log("Player two shot");
                    if (PlayerTwoHealth.DeductHP(Damage))
                    {
                        returnValue = true;
                    }
                    else
                    {
                        playerTwoSlow.ApplyGeneralSlow(0.0f, 8.0f, 0.1f, speedPenalty);
                        HitFlash.FlashCamera(2);
                    }
                }
                CurrentShootInverval -= ShootRate;
            }
            return(returnValue);
        }
コード例 #2
0
        public override bool Fire(Vector3 position, Vector3 direction, float range, int ignoreLayer)
        {
            bool returnValue = false;

            CurrentShootInverval += Time.deltaTime;
            muzzleFlashInterval  += Time.deltaTime;

            // Turn off muzzle flash light
            if (muzzleFlashInterval > 0.05f)
            {
                foreach (GameObject muzzle in muzzleFlash)
                {
                    muzzle.light.enabled = false;
                }
            }

            // Turn off shoot animation state if shoot animation is complete
            if (!droneAnimator.GetCurrentAnimatorStateInfo(1).IsName("Shoot"))
            {
                droneAnimator.SetBool("Shooting", false);
            }

            if (CurrentShootInverval > ShootRate)
            {
                Debug.DrawLine(position, position + (direction * range), Color.red, 2.0f, false);
                CurrentShootInverval -= ShootRate;
                droneAnimator.SetBool("Shooting", true);

                // Shoot sound
                GameObject.Instantiate(droneFireSound, position, Quaternion.identity);

                // Start muzzle flash effect
                foreach (GameObject muzzle in muzzleFlash)
                {
                    muzzle.light.enabled = true;
                    muzzle.particleSystem.Play();
                    muzzleFlashInterval = 0.0f;
                }

                // Raycast in bullet direction
                RaycastHit hit;
                if (Physics.Raycast(position, direction, out hit, 100.0f, ignoreLayer))
                {
                    if (hit.collider.gameObject.tag == "PlayerOne")
                    {
                        HitFlash.FlashCamera(1);
                        if (PlayerOneHealth.DeductHP(Damage))
                        {
                            returnValue = true;
                        }
                    }
                    else if (hit.collider.gameObject.tag == "PlayerTwo")
                    {
                        HitFlash.FlashCamera(2);
                        if (PlayerTwoHealth.DeductHP(Damage))
                        {
                            returnValue = true;
                        }
                    }
                }
            }
            return(returnValue);
        }