首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从用法中推断出方法的类型参数

无法从用法中推断出方法的类型参数
EN

Stack Overflow用户
提问于 2014-04-12 04:37:55
回答 2查看 3K关注 0票数 0

这是我的代码,我正在尝试找出这行代码的问题所在。

.AddComponent()实例=新的游戏实例(“GameObject”);

下面是我得到的错误:The type arguments for method 'UnityEngine.GameObject.AddComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly

代码语言:javascript
运行
复制
using UnityEngine;
using System.Collections;

public class gamestate : MonoBehaviour
{

    //Declare Properties
    private static gamestate instance;

    public static gamestate Instance
    {
        get
        {
            if(instance == null)
            {
                instance = new GameObject( "gamestate").AddComponent ();
            }

            return instance;
        }
    }    

    public void startState()
    {
        print ("Creating a new game state");
    }
}
EN

Stack Overflow用户

发布于 2014-09-30 01:44:27

我想我可能在遵循同样的例子!;-)

您应该更改行:

代码语言:javascript
运行
复制
instance = new GameObject( "gamestate").AddComponent ();

适用于:

代码语言:javascript
运行
复制
instance = new GameObject( "gamestate").AddComponent<gamestate>();

他们的完整代码在这个粘贴板上:http://pastebin.com/YPJTGLwX

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23022137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档