// Update is called once per frame void FixedUpdate() { if ((FindObjectOfType <KillSoldiers> ().transform.position - transform.position).magnitude < killRadius) { GetComponent <HealthComponent>().Health -= 1; } animator.SetFloat("Speed", 1); if (reloadTimer > 0) { reloadTimer -= Time.fixedDeltaTime; } if (target == null || target.IsDead) { target = FindTarget(); } else { if (!AINavigator.CanReachTargetFrom(navigator.navTarget.position, target.gameObject)) { Vector2 sphere = Random.insideUnitCircle; Vector3 sphere2 = new Vector3(sphere.x, 0, sphere.y); navigator.navTarget.position = target.transform.position + sphere2 * distance; } } // Calculate turret's target var turretTarget = turret.GetVisualTarget(); if (turretTarget) { var h = turretTarget.GetComponent <HealthComponent> (); if (h == null) { h = turretTarget.GetComponentInParent <HealthComponent> (); } if (h && h.Team == EnemyTeam) { if (reloadTimer <= 0) { turret.Fire(); reloadTimer = ReloadTime; } } } }
void FixedUpdate() { if (timer > 0) { timer -= Time.fixedDeltaTime; } // Rotate if (target != null) { transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position, new Vector3(0, 1, 0)), MaxRotation * Time.fixedDeltaTime); } if (Input.GetButton("Fire1") && timer <= 0) { turret.Fire(); timer = reload; } }
void FixedUpdate() { if (timer > 0) { timer -= Time.fixedDeltaTime; } // Rotate if (target != null) { transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position, new Vector3(0, 1, 0)), MaxRotation * Time.fixedDeltaTime); } if (Input.GetButton("Fire1") && timer <= 0) { turret.Fire(); timer = reload; animator.SetTrigger("Shoot"); GetComponent <AudioSource>().Play(); } }