示例#1
0
    IEnumerator  disparar()
    {
        if ((Input.GetButtonDown("Fire1") || (KinectManager.instance.IsAvailable && KinectManager.instance.IsFire)))     // && ballInPlay == false){
        {
            couroutineStarted = true;

            fuente.clip = GunSound;
            fuente.Play();

            Rigidbody instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation);
            instantiatedProjectile.velocity = transform.TransformDirection(Vector3.forward * 50);
            Physics.IgnoreCollision(instantiatedProjectile.GetComponent <Collider>(), transform.root.GetComponent <Collider>());

            RaycastHit hit;
            if (Physics.Raycast(puntoDeDisparo.position, puntoDeDisparo.forward, out hit))
            {
                if (hit.transform.CompareTag("Enemigo"))
                {
                    Vida vida = hit.transform.GetComponent <Vida>();
                    if (vida == null)
                    {
                        throw new System.Exception("No se encontro el componente Vida del Enemigo");
                    }
                    else
                    {
                        vida.RecibirDanho(25);
                    }
                }
            }
            yield return(new WaitForSeconds(0.5f));

            couroutineStarted = false;
        }
    }