예제 #1
0
    public void Fire()
    {
        if (fireTimer < fireRate || isReloading || isRunning)
        {
            return;
        }

        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, range))
        {
            InfecteeCtrl enemyCtrl = hit.transform.GetComponent <InfecteeCtrl>();
            Rigidbody    rigidbody = hit.transform.GetComponent <Rigidbody>();


            if (hit.transform.gameObject.tag != "Infectee")
            {
                //Debug.Log("ShotMiss");
                StartCoroutine(FireEffect(hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)));
                TestPlayerAgent1.isShotMiss = true;
            }
            else
            {
                if (enemyCtrl && enemyCtrl.hp > 0)
                {
                    StartCoroutine(BloodEffect(hit.transform.position + Vector3.up * 1.2f));
                }
                //var bP = (GameObject)Instantiate(bloodParticlePrefab, hit.transform.position + Vector3.up * 1.2f, hit.transform.rotation);
            }
            if (enemyCtrl && enemyCtrl.hp > 0)
            {
                enemyCtrl.ApplyDamage(damage);
            }
        }
        else
        {
            //Debug.Log("Miss");
            TestPlayerAgent1.isShotMiss = true;
        }
        currentBullets--;
        fireTimer = 0.0f;
        //anim.CrossFadeInFixedTime("Shoot", 0.01f);
        audioSource.PlayOneShot(shootSound);    //shoot sound
        muzzleFlash.Play();
        //Recoil();
        //StartCoroutine(BulletEffect());
    }
예제 #2
0
 private void Start()
 {
     myInfecteeCtrl = GetComponentInChildren <InfecteeCtrl>();
 }