void Update() { if (combat.IsDead()) { PlayClip(deadClip); Destroy(this); return; } if (cooldown <= 0) { int clipIndex = Random.Range(0, clips.Count - 1); AudioClip clip = clips[clipIndex]; PlayClip(clip); cooldown = cooldownVoice; } cooldown -= Time.deltaTime; }
void Update() { if (enemyCombat.IsDead()) { return; } if (skateparkFound) { if (Vector3.Magnitude(closestSkateparkPosition - transform.position) - 1 < agent.stoppingDistance) { Vector3 direction = (closestSkateparkPosition - transform.position).normalized; direction.y = 0; Quaternion rotation = Quaternion.LookRotation(direction); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 20); animator.SetBool("isRunning", false); ThrowDirt(); return; } animator.SetBool("isRunning", true); agent.SetDestination(closestSkateparkPosition); return; } float closestDistance = float.MaxValue; Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius, skateparkLayer); if (hitColliders.Length > 0) { skateparkFound = true; foreach (Collider collider in hitColliders) { Vector3 position = collider.ClosestPoint(transform.position); float distance = Vector3.Magnitude(position - transform.position); if (distance < closestDistance) { closestDistance = distance; closestSkateparkPosition = position; } } } }