void Update() { if (Input.GetMouseButtonDown(0)) { //an if else statement occurring if the player is out of ammo they cannot shoot any more enemy if (ammo > 0) { ammo--; Vector3 point = new Vector3(playerCam.pixelWidth / 2, playerCam.pixelHeight / 2, 0); Ray ray = playerCam.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { //An if else statement allowing the enemy to be hit by bullets causing them to die when shot. GameObject hitObject = hit.transform.gameObject; Enemy_Shot target = hitObject.GetComponent <Enemy_Shot>(); if (target != null) { target.GotShot(); } else { StartCoroutine(ShotGen(hit.point)); //Launch a coroutine in response to a hit! } } } else { print("click"); } } }
// Update is called once per frame void Update() { Debug.DrawRay(shootPoint.transform.position, shootPoint.transform.forward); if (Input.GetButtonDown("Jump")) { //Vector3 point = new Vector3(playerCam.pixelWidth / 2, playerCam.pixelHeight / 2, 0); Ray ray = new Ray(shootPoint.transform.position, shootPoint.transform.forward); RaycastHit hit; //Debug.DrawRay(shootPoint.transform.forward, Vector3.forward); if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; Enemy_Shot targett = hitObject.GetComponent <Enemy_Shot>(); if (targett != null) { targett.GotShot(); } else { StartCoroutine(ShotGen(hit.point)); // Launch a coroutine in response to a hit! } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(playerCam.pixelWidth / 2, playerCam.pixelHeight / 2, 0); Ray ray = playerCam.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; Enemy_Shot targett = hitObject.GetComponent <Enemy_Shot>(); if (targett != null) { targett.GotShot(); } else { StartCoroutine(ShotGen(hit.point)); // Launch a coroutine in response to a hit! } } } }