// Update is called once per frame void Update() { if (!buildingActive) { return; } if (buildingData.attackData != null && Target.NullTarget(target) && checkForTargets.Expired()) { checkForTargets.Start(1f); target = Target.GetClosestTarget(this.transform.position, "Enemy", buildingData.attackData.attackRange); //target = Target.GetClosestTarget(this.transform.position, "Enemy"); } if (buildingData.attackData != null && !Target.NullTarget(target) && attackManager.AttackReady() && workers > 0) { //Debug.Log("Shooting " + target.name); attackManager.Attack(target); AudioSource.PlayClipAtPoint(audioClip, transform.position + new Vector3(0, 35, 0), 1f); } }
// Update is called once per frame void Update() { //if (!agent.isOnNavMesh) //{ // NavMeshHit hit = new NavMeshHit(); // if(NavMesh.SamplePosition(this.transform.position, out hit, 10f, NavMesh.AllAreas)) // { // this.transform.position = hit.position + new Vector3(0,1,0); // } // else // { // Die(); // return; // } //} if (!setTargetTimer.Expired()) { return; } if (target == null) { resetTarget(); } //if(agent.destination == this.transform.position && agent.destination != targetPosition) //{ // agent.SetDestination(targetPosition); //} if (target != null && nextRangeCheck.Expired()) { if (attacking || attackManager.InRange(target.transform.position)) { attacking = true; if (!agent.isStopped) { agent.isStopped = true; } if (attackManager.AttackReady()) { attackManager.Attack(target); AudioSource.PlayClipAtPoint(audioClip, transform.position + new Vector3(0, 25, 0), 1.0f); } } else { nextRangeCheck.Start(1); if (agent.isStopped) { agent.isStopped = false; } if (agent.velocity == Vector3.zero) { if (stoppedLastTime) { setTarget(Target.GetClosestTarget(this.transform.position, "Building")); } else { stoppedLastTime = true; } } } } }