/// <summary> /// Checks if close to player and does stuff accordingly.</summary> private void Update() { /* * Logic of this: * if close to player: * Look at player * Stop moving * Damage Player * if not close to player: * Start Moving * Stop Damaging */ bool closeToPlayer = Vector3.Distance(transform.position, player.transform.position) < AttackRadius; if (closeToPlayer) { movement.FaceTarget(); movement.CurrentlyMoving = false; if (!damageRoutineRunning) { damageRoutine = StartCoroutine(DamagePlayer(DamagePerDelay, AttackTimeDelay)); } } else //if not close to player: { movement.CurrentlyMoving = true; if (damageRoutineRunning) { StopCoroutine(damageRoutine); damageRoutineRunning = false; } } }
private void Update() { //Look at player. followTarget.FaceTarget(); //Check if pet is close to player, and if so halts a short distance away. if (Vector3.Distance(transform.position, Player.transform.position) < FollowDistance) { followTarget.CurrentlyMoving = false; } else { followTarget.CurrentlyMoving = true; } }