private void KillTarget() { if (AITargetEnemy != null && AITargetEnemy.GetComponent <NPCHealth>().IsAlive()) { player.Shoot(); nextAIActionTime = Time.time + timePerShot; } else { nextCommand = AICommands.FIND; } }
void Update() { if (isLocalPlayer) { if (Input.GetKeyDown(KeyCode.B)) { player.DeactivateAI(); player.CmdTeamAIActivate(false); nextCommand = AICommands.FIND; } if (player.GetAIEnabled()) { if (Time.time > AINextTroopSendTime) { CmdAISendTroops(); } if (Time.time > nextAIActionTime) { if (nextCommand == AICommands.FIND) { AITargetEnemy = FindTarget(); if (AITargetEnemy != null) { nextCommand = AICommands.AIM; } } else if (nextCommand == AICommands.AIM) { MoveTowardsTarget(); } else if (nextCommand == AICommands.KILL) { KillTarget(); } } } else { nextCommand = AICommands.FIND; } } }
private void MoveTowardsTarget() { int currentPath = player.GetCrossbowMotor().ActivePath; int targetPath = AITargetEnemy.GetComponent <AIController>().Path; if (currentPath > targetPath) { player.GetCrossbowMotor().MoveLeft(); nextAIActionTime = Time.time + changeDirectionTime; } else if (currentPath < targetPath) { player.GetCrossbowMotor().MoveRight(); nextAIActionTime = Time.time + changeDirectionTime; } currentPath = player.GetCrossbowMotor().ActivePath; if (currentPath == targetPath) { nextCommand = AICommands.KILL; } }