第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何解決 IEnumerator(Unity, C#) 的錯(cuò)誤?

如何解決 IEnumerator(Unity, C#) 的錯(cuò)誤?

C#
largeQ 2023-09-24 16:32:35
我需要讓我的角色墻運(yùn)行,但我有代碼問題IEnumerator這是用Unity 4.5.xC# 編寫的代碼using UnityEngine;using System.Collections;public class Moving : MonoBehaviour {public float speed = 6.0F;public float jumpSpeed = 8.0F; public float gravity = 20.0F;public float runTime = 1.0f;private Vector3 moveDirection = Vector3.zero;private bool isWallL = false;private bool isWallR = false;private RaycastHit hitL;private RaycastHit hitR;private int jumpCount = 1;IEnumerator afterRun() {    yield return new WaitForSeconds (runTime);    isWallL = false;    isWallR = false;    gravity = 20;}void Update() {    CharacterController controller = GetComponent<CharacterController>();    if (controller.isGrounded) {        jumpCount = 0;        moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));        moveDirection = transform.TransformDirection(moveDirection);        moveDirection *= speed;        if (Input.GetButton("Jump"))            moveDirection.y = jumpSpeed;    }    if (Input.GetKeyDown (KeyCode.Space) && !controller.isGrounded && jumpCount <= 1) {        if (Physics.Raycast (transform.position, -transform.right, out hitL, 1)){            if (hitL.transform.tag == "Wall"){                isWallL = true;                isWallR = false;                jumpCount = 1;                gravity = 0;                StartCoroutine (afterRun);            }        }        if (Physics.Raycast (transform.position, transform.right, out hitR, 1)){            if (hitR.transform.tag == "Wall"){                isWallL = false;                isWallR = true;                jumpCount = 1;                gravity = 0;                StartCoroutine (afterRun);            }        }    }    moveDirection.y -= gravity * Time.deltaTime;    controller.Move(moveDirection * Time.deltaTime);    }}預(yù)計(jì)沒有錯(cuò)誤,但我有兩個(gè):錯(cuò)誤CS1502:UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)'的最佳重載方法匹配有一些無效參數(shù)”和“錯(cuò)誤CS1503:參數(shù)#1'無法將方法組'表達(dá)式轉(zhuǎn)換為類型System.Collections.IEnumerator' 。
查看完整描述

3 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊

代碼中的 afterRun 是一個(gè)函數(shù),但您在調(diào)用它時(shí)不使用括號(hào)。所以:


StartCoroutine (afterRun());

例如:


namespace someNamespace

{?

? ? public class SomeClass

? ? {

? ? ? ? IEnumerator afterRun()

? ? ? ? {

? ? ? ? ? ? yield return new WaitForSeconds(3);? ? ? ? ? ??

? ? ? ? }


? ? ? ? public void Test(IEnumerator enumerator)

? ? ? ? {

? ? ? ? ? ? while(enumerator.MoveNext())

? ? ? ? ? ? {

? ? ? ? ? ? ? ? //do some work

? ? ? ? ? ? }

? ? ? ? }


? ? ? ? public void YoureCode()

? ? ? ? {

? ? ? ? ? ? Test(afterRun());

? ? ? ? }

? ? }


? ? public class WaitForSeconds

? ? {

? ? ? ? public WaitForSeconds(int a)

? ? ? ? {? ? ? ? ? ??

? ? ? ? }

? ? }

}


查看完整回答
反對(duì) 回復(fù) 2023-09-24
?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

為什么不這樣:


private IEnumerator coroutine;

然后設(shè)置并調(diào)用它:


coroutine = afterRun();

StartCoroutine(coroutine);


查看完整回答
反對(duì) 回復(fù) 2023-09-24
?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊

根據(jù) Unity協(xié)程的文檔,看來協(xié)程函數(shù)必須被調(diào)用為StartCoroutine ("afterRun");



查看完整回答
反對(duì) 回復(fù) 2023-09-24
  • 3 回答
  • 0 關(guān)注
  • 344 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)