// Update is called once per frame void Update() { //If shootable, then check to see if attached controller's trigger is pressed if (m_leftattachedHand.grabPinchAction.GetStateDown(m_controllerleft)) { Pulse(.1f, 150, 25, SteamVR_Input_Sources.LeftHand); //Shoot the bullet! //Debug.Log("Gun Trigger Pressed!"); leftGun.PlayOneShot(shoot); GameObject bullet = Instantiate(m_bulletPrefab, m_leftbulletSpawnLocation.transform.position, m_leftbulletSpawnLocation.transform.rotation, GameObject.FindObjectOfType <CarMovementStateMachine>().transform) as GameObject; bullet.GetComponent <Rigidbody>().velocity = (bullet.transform.forward * m_bulletSpeed); //bullet.GetComponent<Rigidbody>().AddForce(bullet.transform.forward * m_bulletSpeed); RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(bullet.transform.position, bullet.transform.forward, out hitInfo) && hitInfo.rigidbody != null && hitInfo.rigidbody.GetComponent <Zombie>() != null) { Zombie zombie = hitInfo.rigidbody.GetComponent <Zombie>(); if (zombie != null && zombie.CompareTag("Obstacle")) { bullet.tag = "Untagged"; zombie.tag = "Untagged"; Destroy(zombie.GetComponent <CapsuleCollider>()); Destroy(zombie.GetComponent <Rigidbody>()); zombie.GetComponent <Animator>().SetBool("Dead", true); GameObject.FindObjectOfType <ScreenController>().PassCorrectAnswer(); } } //m_bulletSound.Play(); Destroy(bullet, m_bulletTravelTime); } if (m_rightattachedHand.grabPinchAction.GetStateDown(m_controllerright)) { Pulse(.1f, 150, 25, SteamVR_Input_Sources.RightHand); //Shoot the bullet! //Debug.Log("Gun Trigger Pressed!"); rightGun.PlayOneShot(shoot); GameObject bullet = Instantiate(m_bulletPrefab, m_rightbulletSpawnLocation.transform.position, m_rightbulletSpawnLocation.transform.rotation, GameObject.FindObjectOfType <CarMovementStateMachine>().transform) as GameObject; bullet.GetComponent <Rigidbody>().velocity = (bullet.transform.forward * m_bulletSpeed); //bullet.GetComponent<Rigidbody>().AddForce(bullet.transform.forward * m_bulletSpeed); RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(bullet.transform.position, bullet.transform.forward, out hitInfo) && hitInfo.rigidbody != null && hitInfo.rigidbody.GetComponent <Zombie>() != null) { Zombie zombie = hitInfo.rigidbody.GetComponent <Zombie>(); if (zombie != null && zombie.CompareTag("Obstacle")) { bullet.tag = "Untagged"; zombie.tag = "Untagged"; Destroy(zombie.GetComponent <CapsuleCollider>()); Destroy(zombie.GetComponent <Rigidbody>()); zombie.GetComponent <Animator>().SetBool("Dead", true); GameObject.FindObjectOfType <ScreenController>().PassCorrectAnswer(); } } //m_bulletSound.Play(); Destroy(bullet, m_bulletTravelTime); } }