Home > Enterprise >  Cannot use in ref or out parameter 'parameter' inside an anonymous method
Cannot use in ref or out parameter 'parameter' inside an anonymous method

Time:04-19

How can I pass the reference value to the inside parameter, I use this parameter below, but I get an error:

Compiler Error CS1628 Cannot use in ref or out parameter 'parameter' inside an anonymous method, lambda expression, or query expression

My code:

void allslider(int s1, ref float ob1,GameObject joint)
{
    sldertag[s1].onValueChanged.AddListener((v) =>
    {
        setslider1(ref v, ref ob1, spine);
    });
}

void setslider1(ref float listener,ref float obsever, GameObject joint)
{
    if (listener < obsever)
    {
        float deta = obsever - listener;

        joint.transform.Position(deta,0, 0);

        obsever = listener;
    }
}

Any ideas?

CodePudding user response:

You can share the ob1 as a static variable, try this.

static float ob1;

void allslider(int s1, float ob1,GameObject joint)
{
    sldertag[s1].onValueChanged.AddListener((v) =>
    {
        setslider1(ref v, ref ob1, spine);
    });
}

void setslider1(ref float listener,ref float obsever, GameObject joint)
{
    if (listener < obsever)
    {
        float deta = obsever - listener;

        joint.transform.Position(deta,0, 0);

        obsever = listener;
    }
}
  • Related