Hi, I’m following the Unit targeting lesson from Unity Multiplayer: Intermediate C# Coding & Networking course but I’m stuck with an error I can’t solve.
I’ve seen another post here with the same error but that topic was closed and so there is no solution there.
I’ve got the same code that is seen in the lesson, I’ve set some debug lgos inside my functions to let me see when it stops and to my surprise the method “CmdSetTarget” is not getting called.
Here’s my code:
public void CmdSetTarget(GameObject targetGameObject)
{
Debug.Log("in CmdSetTarget");
try
{
if (!targetGameObject.TryGetComponent<Targetable>(out Targetable target))
{
Debug.LogError("This game object does NOT have the Targetable component");
}
else
{
Debug.Log("Target set");
this.target = target;
Debug.Log(this.target);
}
}
catch (UnityException error)
{
Debug.LogError(error);
}
}
The code you see above is in the Targeter.cs file.
The following is inside the UnitCommandGiver.cs file.
private void TryTarget(Targetable target)
{
Debug.Log("In TryTarget");
foreach (Unit unit in unitSelectionHandler.selectedUnits)
{
Debug.Log("Setting the target");
unit.GetTargeter().CmdSetTarget(target.gameObject);
}
}
In my case the string “In CmdSetTarget” never shows up in the console.
What could it be the error?