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.PatrolPath != null && ParentAI.CurrentPath == null) { ParentAI.Speed = ParentAI.BaseSpeed; Vector3 target = new Vector3(ParentAI.PatrolPath.Points[ParentAI.PatrolPathIndex].x, ParentAI.PatrolPath.Points[ParentAI.PatrolPathIndex].y, 0); if (Vector3.Distance(ParentAI.transform.position, target) < ParentAI.PatrolPath.PointRadius) { ParentAI.PatrolPathIndex++; } if (ParentAI.PatrolPathIndex >= ParentAI.PatrolPath.Points.Count) { ParentAI.PatrolPathIndex = 0; } ParentAI.Move(ParentAI.PatrolPath.Points[ParentAI.PatrolPathIndex]); } else if (ParentAI.CurrentPath == null) { ParentAI.Speed = ParentAI.BaseSpeed; ParentAI.Move(ParentAI.transform.position + GetRandomDirection()); } }