Argument out of range exception when passing in a function to a constructor in c#

I’m getting an argument out of range exception, and I don’t know why.

class delegate_hold {

    public delegate bool CheckDelegate(Vector3 obj_pos);

    public CheckDelegate del;

    public float value;

    public delegate_hold(CheckDelegate del_2, float f) {

        value = f;

        del = del_2;
    }
}
//later in new class

bool ToTheRightOfMouseDown(Vector3 obj_pos) { return obj_pos.x > MouseClickPosDown.x; }

//stuff

List<delegate_hold> check = new List<delegate_hold>();

//more stuff

check[0] = new delegate_hold(ToTheRightOfMouseDown, land.transform.localScale.x / 2 - -1 * MouseClickPosDown.x);

You need to actually add something to the list first. e.g.

delegate_hold CurDelegateHold = new delegate_hold(ToTheRightOfMouseDown, land.transform.localScale.x / 2 - -1 * MouseClickPosDown.x);

check.Add( CurDelegateHold);
1 Like