Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 统一:名称';实例';在当前上下文中不存在_C#_Unity3d_Instance - Fatal编程技术网

C# 统一:名称';实例';在当前上下文中不存在

C# 统一:名称';实例';在当前上下文中不存在,c#,unity3d,instance,C#,Unity3d,Instance,我一直在关注如何在unity中创建一个2D敌人产卵器问题是它给了我一个错误 the name 'Instance' does not exist in the current context 当我运行此代码时 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 公共类敌人:单一行为 { 公众游戏对象敌人; 浮动randX; 漂浮兰迪; 向量2,该向量用于典当; 公共浮动利率=2f; 浮动nextSpawn=0.0f; 无效更新() { 如果

我一直在关注如何在unity中创建一个2D敌人产卵器问题是它给了我一个错误

the name 'Instance' does not exist in the current context
当我运行此代码时

使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类敌人:单一行为
{
公众游戏对象敌人;
浮动randX;
漂浮兰迪;
向量2,该向量用于典当;
公共浮动利率=2f;
浮动nextSpawn=0.0f;
无效更新()
{
如果(Time.Time>nextSpawn)
{
nextSpawn=Time.Time+sprownrate;
randX=随机范围(-6.36f,6.36f);
randY=随机范围(-4.99f,4.99f);
whereToSpawn=新向量2(randX,randY);
实例(敌人,whereToSpawn,四元数.标识);
}
}
}

我在谷歌上搜索了一下,看了一些文件,但都没用。为什么会出现错误以及如何停止错误?

错误意味着您想调用一个方法,但它不存在,因此您必须像这样创建方法实例:

public class SpawnEnemys : MonoBehaviour
{
    :
    : 
   public void Instance(GameObject enemy, Vector2 wheretoSpawn, Quaternion rotation)
   {
       //Instantiate your Gameobject
       Instantiate(enemy, wheretoSpawn, rotation);
   }
    :
    :
   void Update()
   {
       if (Time.time > nextSpawn)
       {
          :
           Instance (enemy, whereToSpawn, Quaternion.identity);
       }
   }


}

你打错了。您应该调用的方法是实例化,而不是实例
@伊里亚特杜舍夫


你打错了。您应该调用的方法是
实例化
,而不是
实例