예제 #1
0
    void shoot()
    {
        if (varPause == false)
        {
            particle.SetActive(true);
            bullets--;
            ui.updateBullets(bullets, yourBullets);


            if (sounds.isPlaying == false)
            {
                sounds.PlayOneShot(shootSound);
            }


            //A mira irá aparecer na tela independente do tamanho da screen pois o calculo cola a mira no meio
            Ray look = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2f, Screen.height / 2f, 0f));
            RaycastHit hitInfo;

            //O if usando raycast por si só ja retorna algo , caso esse raio colida com algo
            if (Physics.Raycast(look, out hitInfo))
            {

                enemy enemyOK = hitInfo.transform.GetComponent<enemy>();
                if (enemyOK != null)
                {
                    if (enemyOK.tag == "zombie")
                    {

                        enemyOK.dano();
                        Debug.Log("PEEi");
                        blood.Play();
                    }

                }


                if (hitInfo.transform.gameObject.tag != "zombie")
                {
                    Instantiate(hitMarker, hitInfo.point, Quaternion.identity);
                }

            }
        }
        
    }