コード例 #1
0
    public void shoot()
    {
        //falta checkear que el jugador se quedo sin balas
        if (!reloading)
        {
            if (timer >= fireRate)
            {
                if (checkAmmo())
                {
                    //shooting = true;  SAQUE ESTE SHOOTING = TRUE Y HICE QUE REALMENTE SOLO CUANDO ESTE DISPARANDO, CONSULTAR A COZZA SI ESTA BIEN EN CLASE.



                    if (weaponModel == WeaponEnum.Laser && overheatCount < overheatLimit)
                    {
                        audio.clip = shootAudio;
                        audio.Play();
                        modelGameObject.animation.Play();
                        Rigidbody lasInstance = (Rigidbody)Instantiate(proPrefab, spawnPos.position, spawnPos.rotation);
                        lasInstance.AddForce(spawnPos.forward * laserSpeed);
                        lasInstance.GetComponent <Projectile>().setDamage(damage);

                        overHeat();
                        shooting = true;
                        WiiMote.wiimote_rumble(Configuration.pointerWiiMote, (float)0.053);
                    }
                    else if (overheatCount > overheatLimit)
                    {
                        WiiMote.wiimote_rumble(Configuration.pointerWiiMote, (float)1.5);
                    }
                    else if (weaponModel == WeaponEnum.Rifle)
                    {
                        audio.clip = shootAudio;
                        audio.Play();
                        modelGameObject.animation.Play();
                        Vector3 fwd = spawnPos.TransformDirection(Vector3.forward);
                        fwd *= 20;
                        WiiMote.wiimote_rumble(Configuration.pointerWiiMote, (float)0.2);
                        Debug.DrawRay(transform.position, fwd);

                        RaycastHit hit;
                        if (Physics.Raycast(transform.position, fwd, out hit, 9999, 1))
                        {
                            //para cuando queres levantar el arma2
                            if (Round.weaponSpawned && !Round.weaponPicked)
                            {
                                if (hit.collider.GetComponent <Arma>() != null)
                                {
                                    hit.collider.GetComponent <WeaponSpawn>().transitionToPlayer();
                                }
                            }
                            GameObject particleInstance = (GameObject)Instantiate(Projectile.bulletParticle, hit.point, transform.rotation);
                            particleInstance.transform.LookAt(transform.position);
                            Destroy(particleInstance, particleInstance.particleSystem.duration + 0.01f);
                            HealthSystem HP = hit.collider.gameObject.GetComponent <HealthSystem>();

                            if (HP != null)
                            {
                                HP.damageHp(damage);
                            }
                        }
                        shooting = true;
                    }
                    else
                    {
                        shooting = false;
                    }


                    this.bullets -= 1;
                    updateAmmo();

                    if (this.bullets == 0)
                    {
                        showWarning("reload");
                    }
                }
                timer = 0f;
            }
        }
    }