it looks like when i right click on an “Enemy” unit the CmdSetTarget doesn’t get called.
i’ve made many builds and logged at eaceh stage of the code but i get the console message error at CmdSetTarget.
UnitCommandGiver:
public class UnitCommandGiver : MonoBehaviour
{
[SerializeField] private UnitSlectionHandler unitSlectionHandler = null;
[SerializeField] private LayerMask layerMask = new LayerMask();
private Camera mainCamera;
private void Start()
{
mainCamera = Camera.main;
}
private void Update()
{
if (!Mouse.current.rightButton.wasPressedThisFrame) { return; }
Ray ray = mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue());
if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, layerMask)) { return; }
if(hit.collider.TryGetComponent<Targetable>(out Targetable target))
{
if (target.isOwned)
{
TryMove(hit.point);
return;
}
TryTarget(target);
return;
}
TryMove(hit.point);
}
private void TryMove(Vector3 point)
{
foreach (Unit unit in unitSlectionHandler.SelectedUnits)
{
unit.GetUnitMovement().CmdMove(point);
}
}
private void TryTarget(Targetable target)
{
foreach (Unit unit in unitSlectionHandler.SelectedUnits)
{
unit.GetTargeter().CmdSetTarget(target.gameObject);
}
}
}
Targeter:
public class Targeter : NetworkBehaviour
{
[SerializeField] private Targetable target;
#region Server
[Command]
public void CmdSetTarget(GameObject targetGameObject)
{
if (!targetGameObject.TryGetComponent<Targetable>(out Targetable newTarget)) { return; }
target = newTarget;
}
[Server]
public void ClearTarget()
{
target = null;
}
#endregion
#region Client
#endregion
}
Can anyone help?