我的编译器告诉我它无法将'void'转换为'string'我明白这意味着什么,但不知道如何修复它



这里我试图在随机位置实例化定义的GameObject(在RandomPosOne()中定义(

但是我的编译器说

无法从"void"转换为"string">

public class Enemyspawner : MonoBehaviour
{
public GameObject Elf;

private void OnCollisionEnter2D(Collision2D collider)
{
if (collider.gameObject.CompareTag("SpawnTrigger1"))
{
InvokeRepeating((SpawnElfOne()), 2f, 3f);
}
void SpawnElfOne()
{
Instantiate(Elf, RandomPosOne(), Quaternion.identity);
}

}
Vector2 RandomPosOne()
{
float x, y;
x = Random.Range(-8.6f, 8.7f);
y = Random.Range(3.05f, -3.36f);
return new Vector2(x, y);
}
Vector2 RandomPosTwo()
{
float x, y;
x = Random.Range(-8.8f, 8.8f);
y = Random.Range(19f, 12.6f);
return new Vector2(x, y);
}
}

将本地void方法SpawnElfOne移出实例

并在调用CCD_ 5 时将目标方法名称作为CCD_

public class Enemyspawner : MonoBehaviour {
public GameObject Elf;

private void OnCollisionEnter2D(Collision2D collider) {
if (collider.gameObject.CompareTag("SpawnTrigger1")) {
InvokeRepeating("SpawnElfOne", 2f, 3f);
}           
}
void SpawnElfOne() {
Instantiate(Elf, RandomPosOne(), Quaternion.identity);
}

Vector2 RandomPosOne() {
float x, y;
x = Random.Range(-8.6f, 8.7f);
y = Random.Range(3.05f, -3.36f);
return new Vector2(x, y);
}
Vector2 RandomPosTwo() {
float x, y;
x = Random.Range(-8.8f, 8.8f);
y = Random.Range(19f, 12.6f);
return new Vector2(x, y);
}
}

相关内容

  • 没有找到相关文章

最新更新