Gameobject sending task to another gameobject

I’m making a game where the enemy team consists of a queen and two servants.
If the queen dies, her crown drops on the floor and it start scanning for a new queen. The servant who is closest to the crown is marked as the successor.

This part of the script works perfectly, but now I want the CrownScript to send some sort of message to the script of the chosen servant to claim the title of new queen. The servants are using NavMesh to get around.

Well to “send a task” to an other GameObject you can reference it and then set a bool or start a void. But if you have more servants then you can loop through all servants and for example see which one is closest to the crown. Then set his destination of the navmeshSCript, i made a quick example hope it helps a bit:

	//Find all servants that have ServantScript on them
	public ServantScript[] servant = Object.FindObjectsOfType<ServantScript>();

	//when the queen is dead
		//check for all servants in the servants array and loop through
		for(int i = 0; i < servant.Length; i++){
			//get a distance between each servant and the queen
			float dist = Vector3.Distance(transform.position -  servant*.transform.position);*
  •  	if(dist < 10)*
  •  	{*
  •  		//if the servant is closer than 10 then set his navmeshAgent's destination to this position(where the crown is?)*

_ servant*.GetComponent().SetDestination(transform.position);_

Great! That worked :slight_smile: thanks