Cannot implicitly convert type `System.Action' to `bool'

Special Thanks to Marrrrk for this example script:

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class SelectionManager
{
    public List<Unit> _selection = new List<Unit>();
      
    public Action<Unit> UnitSelected;
    public Action<Unit> UnitDeselected;
   
    public void Select(Unit unit)
    {
        if (_selection.Contains(unit))
            return;
              
        _selection.Add(unit);
          
        if (UnitSelected)
            UnitDeselected(unit);
		
    }
      
    public void Deselect(Unit unit)
    {
        if (!_selection.Contains(unit))
            return;
              
           _selection.Remove(unit);
       
        if (UnitSelected)
            UnitSelected(unit);
    }
      
    public static SelectionManager Default = new SelectionManager();
}

There error is when the following line is called
if (UnitSelected)
UnitSelected(unit);

I’ve never used List’s of Action’s before, and I can’t quite figure this out, so thanks for any help.

I guess that this if is there to check if particular action was assigned and is not null. In this case you have to change it to:

if(UnitSelected != null)
{
    UnitSelected(unit);
}

and the same with the UnitDeselected.

Also, please note that you have an error inside Select method - in if condition you check UnitSelected and then you call UnitDeselected.