void Awake() { if (instance != null) { Destroy(gameObject); } else { instance = this; } }
// Update is called once per frame void Update() { if (GameManagerScript.instance.isPaused) { return; } healthBarImage.fillAmount = (float)health / (float)maxHealth; healthBarTransform.LookAt(healthBarTransform.position + Camera.main.transform.rotation * Vector3.back, Camera.main.transform.rotation * Vector3.down); if (objRenderer.isVisible && Input.GetMouseButton(0) && friendly && (Mathf.Abs(CameraOperatorScript.selectionbox.width) > 0.5f || Mathf.Abs(CameraOperatorScript.selectionbox.height) > 0.5f)) { Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position); camPos.y = CameraOperatorScript.InvertMouseY(camPos.y); selected = CameraOperatorScript.selectionbox.Contains(camPos); if (selected) { objRenderer.material.color = Color.red; if (!CameraOperatorScript.instance.selectedUnitList.Contains(this)) { CameraOperatorScript.instance.selectedUnitList.Add(this); } } else { if (CameraOperatorScript.instance.selectedUnitList.Contains(this)) { CameraOperatorScript.instance.selectedUnitList.Remove(this); } objRenderer.material.color = Color.white; } } if (CameraOperatorScript.instance.inputState == TouchInputState.UNITSELECT) { if (friendly) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.transform == this.transform) { for (int i = 0; i < CameraOperatorScript.instance.selectedUnitList.Count; i++) { CameraOperatorScript.instance.selectedUnitList[i].selected = false; CameraOperatorScript.instance.selectedUnitList[i].objRenderer.material.color = Color.white; } CameraOperatorScript.instance.selectedUnitList.Clear(); if (!selected) { selected = true; objRenderer.material.color = Color.red; CameraOperatorScript.instance.selectedUnitList.Add(this); } } } } } } fireCountdown -= Time.deltaTime; if (target != null) { if (enemy == null) { enemy = target.GetComponent <TurretScript>(); } if (!enemy.isAlive) { target = null; enemy = null; return; } targetPos = target.transform.position; if (fireCountdown <= 0f) { fireCountdown = 1f / fireRate; if (Vector3.Distance(transform.position, targetPos) <= range) { navMeshAgent.isStopped = true; canMove = false; StopCoroutine(RepathRoutine()); enemy.TakeDamage(damage); } } } }