我一直在关注a tutorial如何统一创建2D敌方生成器,问题是它给了我错误
the name 'Instance' does not exist in the current context
当我运行此代码时
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnEnemys : MonoBehaviour
{
public GameObject enemy;
float randX;
float randY;
Vector2 whereToSpawn;
public float spawnRate = 2f;
float nextSpawn = 0.0f;
void Update()
{
if (Time.time > nextSpawn)
{
nextSpawn = Time.time + spawnRate;
randX = Random.Range(-6.36f, 6.36f);
randY = Random.Range(-4.99f, 4.99f);
whereToSpawn = new Vector2(randX, randY);
Instance (enemy, whereToSpawn, Quaternion.identity);
}
}
}
我用Google搜索它并阅读了一些文档,但它们没有帮助。为什么我得到该错误以及如何停止该错误?
实例是一种方法,您必须创建类似这样的内容:
public class SpawnEnemys : MonoBehaviour
{
:
:
public void Instance(GameObject enemy, Vector2 wheretoSpawn, Quaternion rotation)
{
//Instantiate your Gameobject
Instantiate(enemy, (Vector3) wheretoSpawn, rotation);
}
:
:
}