I am trying to make a simple dash for my character but there is an issue (i use unity's new input system)

huangapple go评论135阅读模式
英文:

I am trying to make a simple dash for my character but there is an issue (i use unity's new input system)

问题

基本上,我正在尝试编写一段代码,当按下时,使 "dashing" 布尔值在 0.2 秒内变为 true,但我无法调用 IEnumerator dash()。(我使用Unity的新输入系统)

public void dash(InputAction.CallbackContext context)
{
    if (context.performed)
        StartCoroutine("dash");
}

IEnumerator dash()
{
    dashing = true;
    yield return new WaitForSeconds(0.2f);
    dashing = false;
}
英文:

So basically i am trying to do a code that makes "dashing" bool, true for 0.2 sec when pressed. but i cannot call the IEnumerator dash(). (i use unity's new input system)

public void dash(InputAction.CallbackContext context)
    {
        if (context.performed)
            StartCoroutine("dash");
    }

    
    IEnumerator dash()
    {
        dashing = true;
        yield return new WaitForSeconds(0.2f);
        dashing = false;
    }

答案1

得分: 1

只返回翻译好的部分:

"this is not the correct way to call a coroutine, it should do something like this:

StartCoroutine(dash());
Or this:

IEnumerator coroutine = dash();
StartCoroutine(coroutine);
Hope this helps!"

英文:

>StartCoroutine("dash");

this is not the correct way to call a coroutine, it should do something like this:

StartCoroutine(dash());

Or this:

IEnumerator coroutine = dash();
StartCoroutine(coroutine);

Hope this helps!

huangapple
  • 本文由 发表于 2023年3月7日 02:59:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75654788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定