TransWikia.com

What is causing the error "the best overloaded method match for 'UnityEngine.WaitUntil.WaitUntil(system.func) has some invalid arguments"?

Stack Overflow Asked by HiddenToad on December 3, 2020

I am trying to make a basic controller engine. I made a bool variable called JumpWait to wait to be able to jump until touching ground. Here is my code:

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

public class TwoDController : MonoBehaviour
{

    public float speed;
    public int Jumps;
    public bool InAir = false;

    void OnCollisionEnter2D(Collision2D otherObj)
    {
        if (otherObj.gameObject.CompareTag("Ground"))
        {
            Jumps = 0;
        }
    }

    private void Update()
    {

        if (Jumps == 0)
        {
            InAir = false;
        }
        if (Input.GetKey("a"))
        {
            transform.Translate(Vector3.left * speed * Time.deltaTime);
        }

        if (Input.GetKey("d"))
        {
            transform.Translate(Vector3.right * speed * Time.deltaTime);
        }
        if (Input.GetKey("w"))
            Jumps += 1;
        {
            if (Jumps >= 1)
            {
                StartCoroutine("JumpWait");
                transform.Translate(Vector3.up * speed * Time.deltaTime);
            }
        }

    }
    IEnumerator JumpWait()
    {
        yield return (new WaitUntil(InAir = false));


    }
}

Could someone PLEASE help me out? i have been trying this for hours

One Answer

Welcome to StackOverflow!

Seems you need a little bit of help with what MethodName(Func<T>) means. Take a look at the code below:

    private bool inAir = false;
    
    //This is what your WaitUntil looks like: 
    public bool FakeWaitUntil(Func<bool> someMethod)
    {
        bool someVar = someMethod();
        return someVar;
    }
    
    //You need to create a method that returns bool
    public bool MyMethod()
    {
        return inAir;
    }
    
    public void UsageOfFakeUntil()
    {
        //This is how it is used:
        FakeWaitUntil(MyMethod);

        //Or a dirtier (IMHO) implementation using anonymous functions:
        FakeWaitUntil(() => { return inAir; });
    }

    

WaitUntil is expecting a method that returns a bool, or a delegate. It seems WaitUntil is expecting you to process something before taking action on it, in your case you might need to process InAir.

More profound information can be found here

Correct answer by Kristianne Nerona on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP