Control Units in Battle

👍

Reminder - Keep Daily Backups

When working on a strategy game with a kit as big as the Complete Kit - always keep a working daily backup! Save yourself the trouble of rolling-back changes and losing work.

What are unit controls?

The City Building Pro and Complete Strategy Kits comes with unit controls.

893

Left side controls

These options allow your players to manually deploy and control up to 4 groups of troops in battles to override the AI which automatically controls battle units for players if they do nothing.

With these groups, players can strategically attack enemy bases. For example, selecting the gold mines or defense structure first to attack.

441

About the UI

ControlsDescription
Group #The group number button. From 1 to 4. Tap to control (group number turns red). Units in the group have a small light designator above their sprites when they are being controlled so you can tell the difference between other group units.
Units in GroupThe number of remaining units in the group. This number decreases as the units are killed by the enemy base defenses. When it reaches 0, the group can no longer be controlled and a message will appear in the Chimera PvP Debugger "Sorry, sir. Squad # has been lost. Disabling controls."

What happens if players don't control units?

By default, the City Building Kit Helios.cs script automatically controls all battle AI. This includes troop actions. Immediately after deployment the group is automatically assigned its first target. Manual controls allow you to override this - but even if you disable controls, the game still functions because by default, like the defense structures, the troops are controlled by the AI and pathfinding scripts throughout the battle.

So if you just want to have automated battle gameplay like popular free-to-play battle games - disable the unity group controls with the instructions below.

How can I control units in battle?

StepsDescription
Step 1First open the Unit panel
Step 2Select which units you want to deploy
Step 3Then click a block on the map. The grid point will become highlighted with a glow.
Step 4hen press the yellow Deploy to deploy the group, or the yellow DOWN arrow on the right side of the menu (depends on your kit version)

The following is a visual walkthrough of deploying and controlling a unit group to attack an archer tower. First, when you enter the battle you want to open the army unit menu. Select the army unit button on the right. (The number under the button signifies how much of your army you have left to deploy)

378

Click to open the army menu in battle

When the menu opens, select the troops you want to deploy.

967

Select the troops you want to deploy

Then pick a spot on the map, afterwards, press the Deploy button. (In the newer versions of the kit - this is a yellow DOWN arrow on the right side of the unit menu)

967

Pick a spot to deploy

👍

Automatic Troop AI

If you don't control units after you deploy them in battle - the Helios.cs script will automatically control the group for you - selecting the nearest building to attack.

After you have deployed your unit group, you can control them by selecting the group number on the right side. If you have only deployed one unit group, by default, the group is already selected as seen in the below screenshot.

788

Select group

When selected - you will see a small glow above the unit's HP bar as seen in the below screenshot. This allows you to identify which units are in the group because sometimes units groups can be attacking the same structure or move around the map and you'll forget who is in what group.

788

Glow above Units

When you have a unit group selected - tap any enemy player building to control that group. When successfully tapped, buildings will momentarily respond with a small jump animation to signify that the group has been given the command to attack that building. Your unit group automatically navigate to attack the building.

788

Tap building

What scripts are involved?

Scripts/Helios/Helios.cs controls all of the major battle functions. This one centralized script is your powerhouse engine for everything battle related.

Can I disable unit controls? I only want automatic AI units

If you don't control units after you deploy them in battle - the Helios.cs script will automatically control the group for you - selecting the nearest building to attack. You can disable the unit controls and the City Building Kit battle scripts will still function normal because of Helios.cs.

UnitGroupBt[0].SetActive(true);

Here's how you can disable Unit Controls. The following DeployUnits() function is called by Scripts/Menu/Army/MenuArmyBattle.cs when deploying troops from the army menu in battle.

During this process, the buttons for unit controls are initiated in the Helios.cs script. The following is our easy recommendation to disable these buttons to disable unit controls during battle:

// MenuArmyBattle.cs excerpt
// The following function triggers when deploying units during battle
// And to remove unit controls, you want to disable
// the switch cases at the end of this function
// Like the example at the bottom of this page

public void DeployUnits()
{
	if (deploying)
	{
		((Messenger)heliosMsg).DisplayMessage("Deployment in progress. Please wait.");
		return;
	}

	Delay ();//brief delay to prevent stars from appearing under the menus or select building target at the same time
	if (starList.Count == 0)
	{
		((Messenger)heliosMsg).DisplayMessage("Select the location on the edge of the map.");
		return;//insert message
	}
		if (((Helios)helios).instantiationGroupIndex >= 3)	//already deployed all 4 groups
	{
		((Messenger)heliosMsg).DisplayMessage("You already deployed all 4 squads.");
		return;
	}
		if(!((Helios)helios).networkLoadReady)						//map not loaded yet - don't deploy
	{
		((Messenger)statusMsg).DisplayMessage("Map is not loaded or internet connection failed.");
		return;//insert messages
	}

	bool someUnitSelected = false;

  // Check if there are actually units selected
	for (int i = 0; i < unitsNo; i++) 
	{
		if(((StatsBattle)statsBattle).deployedUnits [i] != 0)
		{
			someUnitSelected = true;
			break;
		}
	}

	if (!someUnitSelected) //user has not selected any unit to deploy
	{
		((Messenger)heliosMsg).DisplayMessage("Assign units to the squad.");
		return;										
	}
			
  // Open a new group in helios
	((Helios)helios).instantiationGroupIndex++;
	
	if(((Helios)helios).instantiationGroupIndex!=0)
		((Helios)helios).selectedGroupIndex++;

	((Relay)relay).deploying = true;

 // manages the last deployed group
	switch (((Helios)helios).instantiationGroupIndex) 
	{
      // Remove these cases if you would like to disable group controls
      // The UnitGroupBt[X].SetActive(true); enables the unit buttons
      // And the ((Helios)helios).SelectX(); selects the group for control
      // By disabling both of these lines -- the group won't be selected for
      // control and the button won't show on the left side.
      
	case 0:
		tempList=((Helios)helios).GroupO;
		((Helios)helios).Select0();
		UnitGroupBt[0].SetActive(true);
		break;
	case 1:
		tempList=((Helios)helios).GroupI;
		((Helios)helios).Select1();
		UnitGroupBt[1].SetActive(true);
		break;
	case 2:
		tempList=((Helios)helios).GroupII;
		((Helios)helios).Select2();
		UnitGroupBt[2].SetActive(true);
		break;
	case 3:
		tempList=((Helios)helios).GroupIII;
		((Helios)helios).Select3();
		UnitGroupBt[3].SetActive(true); /
		break;
	}		
	
	closeBt.SetActive (false);
	spawnIndex = 0;
	unitTypeIndex = 0;
	speedModifier = 0.2f;		//puts some distance between units while walking
	deploying = true;

}

As you saw in the function excerpt above, at the end of deploying the UnitGroupBt in the UI is activated and the Helios.cs script is called to select the group just activated. By commenting out these two lines for each of the four group cases, you can disable unit controls from appearing and from groups being selected.

See the below example:

switch (((Helios)helios).instantiationGroupIndex) 			//manages the last deployed group
	{
      // Remove these cases if you would like to disable group controls
      // The UnitGroupBt[X].SetActive(true); enables the unit buttons
      // And the ((Helios)helios).SelectX(); selects the group for control
      // By disabling both of these lines -- the group won't be selected for
      // control and the button won't show on the left side.
      
      // For example, see the commented out sections below:
      
	case 0:
		tempList=((Helios)helios).GroupO;
		//((Helios)helios).Select0();
		//UnitGroupBt[0].SetActive(true);
		break;
	case 1:
		tempList=((Helios)helios).GroupI;
		//((Helios)helios).Select1();
		//UnitGroupBt[1].SetActive(true);
		break;
	case 2:
		tempList=((Helios)helios).GroupII;
		//((Helios)helios).Select2();
		//UnitGroupBt[2].SetActive(true);
		break;
	case 3:
		tempList=((Helios)helios).GroupIII;
		//((Helios)helios).Select3();
		//UnitGroupBt[3].SetActive(true); /
		break;
	}