Ejemplo n.º 1
0
    //
    void FixedUpdate()
    {
        Vector2    bulletOffset = Random.insideUnitCircle * UIDynamicCrosshair.spread;
        Ray        ray          = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2 + bulletOffset.x, Screen.height / 2 + bulletOffset.y, 0));
        RaycastHit hit;

        if (attack == true)
        {
            attack = false;
            source.PlayOneShot(attackSound);
            StartCoroutine("Attack");
            if (Physics.Raycast(ray, out hit, range, -5, QueryTriggerInteraction.Ignore))
            {
                Debug.Log("Попали в коллайдер " + hit.collider.gameObject.name);
                //hit.collider.gameObject.SendMessage("pistolHit", pistolDamage, SendMessageOptions.DontRequireReceiver);
                EnemyHealthAndArmor enemy = hit.collider.GetComponent <EnemyHealthAndArmor>();
                if (enemy != null)
                {
                    enemy.Damage((int)damage, hit);
                }

                ObjectProperty envir = hit.collider.GetComponent <ObjectProperty>();
                if (envir != null)
                {
                    envir.Hit((int)damage, hit);
                }
            }
        }
    }
Ejemplo n.º 2
0
    void FixedUpdate()
    {
        RaycastHit hit;

        if (isShot == true && ammoClipLeft > 0 && isReloading == false)
        {
            isShot = false;
            UIDynamicCrosshair.spread += UIDynamicCrosshair.PISTOL_SHOOTING_SPREAD;
            ammoClipLeft--;
            source.PlayOneShot(shotSound);
            StartCoroutine("Shot");
            for (int b = 0; b < pellets; b++)
            {
                Vector2 bulletOffset = Random.insideUnitCircle * UIDynamicCrosshair.spread * 2;
                Ray     ray          = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2 + bulletOffset.x, Screen.height / 2 + bulletOffset.y, 0));
                if (Physics.Raycast(ray, out hit, shootgunRange, -5, QueryTriggerInteraction.Ignore))
                {
                    Debug.Log("Попали в коллайдер " + hit.collider.gameObject.name);
                    //hit.collider.gameObject.SendMessage("pistolHit", pistolDamage, SendMessageOptions.DontRequireReceiver);
                    EnemyHealthAndArmor enemy = hit.collider.GetComponent <EnemyHealthAndArmor>();
                    if (enemy != null)
                    {
                        enemy.Damage((int)shootgunDamage, hit);
                    }

                    ObjectProperty envir = hit.collider.GetComponent <ObjectProperty>();
                    if (envir != null)
                    {
                        envir.Hit((int)shootgunDamage, hit);
                    }
                }
            }
        }
        else if (isShot == true && ammoClipLeft <= 0 && isReloading == false)
        {
            isShot = false;
            Reload();
        }
    }