public override void Update() { if (ParentAI.Target == null) { ParentAI.ClearActions(new AILookForPlayer()); ParentAI.AddAction(new AIWander()); End(); return; } if (Time.time - lastSync > 2) { float distance = Helper.DistanceFloatFromTarget(ParentAI.Target.transform.position, ParentAI.transform.position); if (distance < ParentAI.Attack.Range) { ParentAI.AddAction(new AIAttack()); } else if (distance < ParentAI.VisionRange) { ParentAI.Speed = ParentAI.BaseSpeed * 3.3f; ParentAI.Move(ParentAI.Target.transform.position); } else { ParentAI.AddAction(new AILookForPlayer()); ParentAI.AddAction(new AIWander()); ParentAI.Target = null; End(); } lastSync = Time.time; } }
public override void Update() { if (ParentAI.Target == null) { ParentAI.ClearActions(new AILookForPlayer()); ParentAI.AddAction(new AIWander()); End(); return; } else { ParentAI.Stop(ParentAI.Attack.Attack(ParentAI.Target)); End(); } }
public override void Update() { if (Time.time - lastCheck > checkFrequency) { GameObject playerTarget = null; float playerDistance = maxDistanceToCheck; Vector3 pos = ParentAIGameObject.transform.position; GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); for (int i = 0; i < players.Length; i++) { float currentPDistance = Helper.DistanceFloatFromTarget(players[i].transform.position, pos); if (currentPDistance < playerDistance) { RaycastHit2D hit = Physics2D.Raycast(ParentAI.transform.position, players[i].transform.position, currentPDistance, ParentAI.Avoid); Debug.Log("Trying to find player"); if (hit.collider == null) { Debug.Log("Player found"); playerDistance = currentPDistance; playerTarget = players[i]; } } } if (playerTarget != null) { ParentAI.ClearActions(new AIChaseTarget()); ParentAI.Target = playerTarget; } lastCheck = Time.time; } base.Update(); }