我是C#和编程的新手,而且在协同工作时遇到了困难,我之前使用过基本协议,并且没有任何问题,现在我正试图做一些非常相似的事情,但没有任何成功。从统一性当我试图运行协程时,我总是收到错误
错误消息:
参数#1' cannot convert
方法组 '表达键入`System.Collections.IEnumerator'
最好重载方法用于`UnityEngine.MonoBehaviour.StartCoroutine(匹配System.Collections中。 IEnumerator的)”有一些无效参数
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Fire : MonoBehaviour
{
public Transform firePos;
public GameObject bullet;
public bool fireCheck;
public float spawnTime;
IEnumerator FireRate()
{
while(fireCheck == true)
{
yield return new WaitForSeconds(spawnTime);
Instantiate(bullet, firePos.position, firePos.rotation);
}
}
void Start()
{
spawnTime = 4f;
StartCoroutine(FireRate)();
}
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
fireCheck = true;
}
}
}
我会继续研究和更好地理解这一点,但我实在不明白这一点,修复,将不胜感激
这'StartCoroutine(FireRate)(告知自己更多的协同程序);'需要是这样的:'StartCoroutine(FireRate());' – DavidG