protected override void Update() { bool reachedDest = agent.remainingDistance <= agent.stoppingDistance; switch (status) { case Status.IsAttackingTower: base.Update(); if (currentAttackedEnemy == null) { agent.SetDestination(currentPointOfDestination); status = Status.IsOnNormalPath; } if (currentAttackedEnemy.gameObject.GetComponent <HomeBase>() != null) { status = Status.IsAttackingHomeBase; } break; case Status.IsOnNormalPath: if (reachedDest) { status = Status.IsSearchingForNextNode; } break; case Status.IsSearchingForNextNode: currentDestinationNode = currentDestinationNode.GetRandomNextNode(); if (currentDestinationNode != null) { currentPointOfDestination = currentDestinationNode.GetRandomDestination(); agent.SetDestination(currentPointOfDestination); status = Status.IsOnNormalPath; } else { status = Status.ReachedHomeBase; } break; case Status.IsAttackingHomeBase: base.Update(); break; } }
protected override void OnEnable() { currentDestinationNode = null; startingHealth = agentInfo.startingHealth; basicHealthRegen = agentInfo.basicHealthRegen; armor = agentInfo.armor; recoveryAfterBeingDamaged = agentInfo.recoveryAfterBeingDamaged; god = agentInfo.god; if ((int)god > 3) { throw new System.Exception("There can't be a Mars or Mercury agent"); } timeBetweenAttacks = agentInfo.timeBetweenAttacks; attackDamage = agentInfo.attackDamage; range = agentInfo.range; if (Controller.Instance.GetGameState() != 1) { foreach (NavigationNode node in FindObjectsOfType <NavigationNode>()) { if (node.tag == agentInfo.god.ToString()) { currentDestinationNode = node; break; } } currentPointOfDestination = currentDestinationNode.GetRandomDestination(); agent = GetComponent <NavMeshAgent>(); agent.speed = agentInfo.speed; agent.SetDestination(currentPointOfDestination); status = Status.IsOnNormalPath; } base.OnEnable(); }