Example #1
0
    private void Fire()
    {
        Transform cam = Camera.main.transform;

        mNextFire = Time.time + mFireRate;

        Vector3 rayOrigin = cam.position;

        mLaserLine.SetPosition(0, transform.up * -10f);

        RaycastHit hit;

        if (Physics.Raycast(rayOrigin, cam.forward, out hit, mFireRange))
        {
            mLaserLine.SetPosition(1, hit.point);

            CubeBehaviorScript  cubeCtr  = hit.collider.GetComponent <CubeBehaviorScript>();
            CubeBehaviorScript2 cubeCtr2 = hit.collider.GetComponent <CubeBehaviorScript2>();
            if (cubeCtr != null)
            {
                if (hit.rigidbody != null)
                {
                    contador = contador + 5;
                    Debug.Log("Tiro");
                    Debug.Log("Contador " + contador);
                    puntuacion.text = "Marcador: " + contador;
                    hit.rigidbody.AddForce(-hit.normal * mHitForce);
                    cubeCtr.Hit(mLaserDamage);
                }
            }

            if (cubeCtr2 != null)
            {
                if (hit.rigidbody != null)
                {
                    Debug.Log("Incorrecto");
                    hit.rigidbody.AddForce(-hit.normal * mHitForce);
                    cubeCtr2.Hit(mLaserDamage);
                }
            }
        }
        else
        {
            mLaserLine.SetPosition(1, cam.forward * mFireRange);
        }

        StartCoroutine(LaserFx());
    }
Example #2
0
    private void Fire()
    {
        Transform cam = Camera.main.transform;

        mNextFire = Time.time + mFireRate;

        Vector3 rayOrigin = cam.position;

        mLaserLine.SetPosition(0, transform.up * -10f);

        RaycastHit hit;

        if (Physics.Raycast(rayOrigin, cam.forward, out hit, mFireRange))
        {
            NPalabra = Random.Range(1, LimiteRango);

            mLaserLine.SetPosition(1, hit.point);

            CubeBehaviorScript  cubeCtr  = hit.collider.GetComponent <CubeBehaviorScript>();
            CubeBehaviorScript2 cubeCtr2 = hit.collider.GetComponent <CubeBehaviorScript2>();
            if (cubeCtr != null)
            {
                if (hit.rigidbody != null)
                {
                    contador = contador + 5;
                    Debug.Log("Tiro");
                    Debug.Log("Contador " + contador);
                    puntuacion.text = "Marcador: " + contador;
                    hit.rigidbody.AddForce(-hit.normal * mHitForce);
                    cubeCtr.Hit(mLaserDamage);
                    AsignarPalabras(NPalabra);
                }
            }

            if (cubeCtr2 != null)
            {
                if (hit.rigidbody != null)
                {
                    vida = vida - 1;
                    Debug.Log("Incorrecto");
                    hit.rigidbody.AddForce(-hit.normal * mHitForce);
                    cubeCtr2.Hit(mLaserDamage);
                    AsignarPalabras(NPalabra);
                }
            }

            if (vida <= 0)
            {
                Vida1.enabled           = false;
                puntuacionFinal.enabled = true;
                puntuacionFinal.text    = "Puntuacion Total: " + contador;
                //Application.Quit();
            }
            if (vida == 3)
            {
                Vida1.enabled = true;
                Vida2.enabled = true;
                Vida3.enabled = true;
            }
            if (vida == 2)
            {
                Vida1.enabled = true;
                Vida2.enabled = true;
                Vida3.enabled = false;
            }
            if (vida == 1)
            {
                Vida1.enabled = true;
                Vida2.enabled = false;
                Vida3.enabled = false;
            }
        }
        else
        {
            mLaserLine.SetPosition(1, cam.forward * mFireRange);
        }

        StartCoroutine(LaserFx());
    }