示例#1
0
 private void Celebrate()
 {
     if (Random.Range(0, 100) > chanceToCelebrate)
     {
         return;
     }
     audioSource.ForcePlay(happySounds[Random.Range(0, happySounds.Length)]);
 }
示例#2
0
    public IEnumerator Shoot()
    {
        if (canShoot)
        {
            // enemyTransform = GameManager.Instance.GetClosestEnemy();
            Vector3 mousePos = Input.mousePosition;
            mousePos.z = mainCam.transform.position.z;
            mousePos   = mainCam.ScreenToWorldPoint(mousePos);

            DisablePointingArms();

            if (mousePos.x > ownTransform.position.x)
            {
                rightArm.gameObject.SetActive(true);
                leftArm.gameObject.SetActive(false);
                restingRightArm.enabled = false;
                restingLeftArm.enabled  = true;
                currentArm = rightArm;

                if (PointArmToTarget(currentArm, mousePos) < rightArmAngleLimit)
                {
                    activeRightArmLower.gameObject.SetActive(true);
                }
                else
                {
                    activeRightArmUpper.gameObject.SetActive(true);
                }

                particlesTransform.position = rightHand.transform.position;
            }
            else
            {
                rightArm.gameObject.SetActive(false);
                leftArm.gameObject.SetActive(true);
                restingRightArm.enabled = true;
                restingLeftArm.enabled  = false;
                currentArm = leftArm;

                if (PointArmToTarget(currentArm, mousePos) > leftArmAngleLimit)
                {
                    activeLeftArmLower.gameObject.SetActive(true);
                }
                else
                {
                    activeLeftArmUpper.gameObject.SetActive(true);
                }

                particlesTransform.position = leftHand.transform.position;
            }

            particlesTransform.LookAt(mousePos, Vector3.up);
            Collider2D collider      = Physics2D.OverlapCircle(mousePos, castRadius, enemyDetectMask);
            bool       enemyDetected = false;

            audioSource.ForcePlay(pistolSounds[Random.Range(0, pistolSounds.Length)]);

            if (collider)
            {
                enemyDetected = true;
            }

            shotParticles.Play();
            StartCoroutine(CooldownShooting());

            if (enemyDetected)
            {
                yield return(new WaitForSeconds(shotImpactDelay));

                collider.GetComponent <Enemy>().OnHit();
            }
        }
    }