这是我的代码,我正在尝试找出这行代码的问题所在。
.AddComponent()实例=新的游戏实例(“GameObject”);
下面是我得到的错误:The type arguments for method 'UnityEngine.GameObject.AddComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly
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");
}
}发布于 2014-09-30 01:44:27
我想我可能在遵循同样的例子!;-)
您应该更改行:
instance = new GameObject( "gamestate").AddComponent ();适用于:
instance = new GameObject( "gamestate").AddComponent<gamestate>();他们的完整代码在这个粘贴板上:http://pastebin.com/YPJTGLwX
https://stackoverflow.com/questions/23022137
复制相似问题