}// end of OnEnable private void HandleDown() { // if there is an interactible currently being looked at MosquitoController shootingMosquito = m_EyeRaycaster.CurrentInteractible ? m_EyeRaycaster.CurrentInteractible.GetComponent <MosquitoController>() : null; // get target transform Transform target = shootingMosquito ? shootingMosquito.transform : null; // Start shooting coroutine StartCoroutine(Fire(target)); }// end of HandleDown
void Update() { float cooldownPercentage = Mathf.Clamp(((Time.time - lastShotTime) / delayBetweenShots), 0, 1); cooldownBar.localScale = new Vector3(cooldownPercentage * 28, 2, 1); //Debug.Log(cooldownPercentage); if (mosquitoesEngagedMode) { timer -= Time.deltaTime; if (timer <= 0) { lerpPosition(); } else { transform.localPosition = Vector3.SmoothDamp(transform.localPosition, targetPosition, ref velocity, 0.5f); //transform.localPosition = Vector3.MoveTowards(transform.localPosition, targetPosition, aimSpeed); } } else { transform.localPosition = Vector3.SmoothDamp(transform.localPosition, initialLocalPos, ref velocity, 0.5f); } if (Input.GetKeyDown(KeyCode.Alpha3)) { if ((Time.time - lastShotTime > delayBetweenShots)) { lastShotTime = Time.time; RaycastHit hit; Vector3 dir = transform.position - killingCamera.transform.position; swatAnimationAndSound(); int layerMask = 1 << 15; //try to hit mosquitos only. if (Physics.Raycast(killingCamera.transform.position, dir, out hit, HitmaxDistance, layerMask)) { //Debug.Log("hit!"); GameObject mosquito = hit.transform.gameObject; MosquitoController mosquitoController = mosquito.GetComponent <MosquitoController>(); int MosquitoeNumber = mosquitoController.MosquitoeNumber; ExterminationManager.SharedInstance.MosquitoeHit(MosquitoeNumber); hit.transform.gameObject.SetActive(false); } } } }
private void SpawnMosquitos() { GameObject tmp; for (int i = 0; i < amountToPool; i++) { tmp = Instantiate(objectToPool); tmp.SetActive(false); pooledObjects.Add(tmp); } for (int i = 0; i < amountToPool; i++) { GameObject mosquito = GetPooledObjectByIndex(i); MosquitoController mosquitoController = mosquito.GetComponent <MosquitoController>(); mosquito.transform.position = NewRandomPosition(); mosquitoController.MosquitoeNumber = i; mosquito.SetActive(true); } }