本文整理汇总了C#中GameObject.GetOrCreateComponent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetOrCreateComponent方法的具体用法?C# GameObject.GetOrCreateComponent怎么用?C# GameObject.GetOrCreateComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetOrCreateComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static void Create()
{
if ( Selection.activeGameObject != null )
{
GameObject path = new GameObject ( "Path" );
path.GetOrCreateComponent<PointPath> ();
if ( Selection.activeGameObject.transform.parent != null )
path.transform.parent = Selection.activeGameObject.transform.parent.transform;
path.transform.position = Selection.activeGameObject.transform.position;
PathFollower pathFollower = Selection.activeGameObject.GetOrCreateComponent<PathFollower> ();
pathFollower.Path = path;
}
}
示例2: CreateNinePatch
public static void CreateNinePatch()
{
GameObject go = new GameObject ();
go.name = "NinePatch";
/* NinePatch ninePatch = */ go.GetOrCreateComponent<NinePatch> ();
if ( Selection.activeGameObject != null )
{
go.transform.parent = Selection.activeGameObject.transform;
go.transform.position = Selection.activeGameObject.transform.position;
}
Selection.activeObject = go;
}
示例3: CreateQuad
public static void CreateQuad()
{
GameObject go = new GameObject ();
go.name = "Quad";
/* Quad quad = */ go.GetOrCreateComponent<Quad> ();
if ( Selection.activeGameObject != null )
{
go.transform.parent = Selection.activeGameObject.transform;
go.transform.position = Selection.activeGameObject.transform.position;
}
Selection.activeObject = go;
}
示例4: CreateTextMeshEx
public static void CreateTextMeshEx()
{
GameObject go = new GameObject();
go.name = "Text";
TextMeshEx textMesh = go.GetOrCreateComponent<TextMeshEx> ();
textMesh.Font = Resources.GetBuiltinResource ( typeof ( Font ), "Arial.ttf" ) as Font;
if ( Selection.activeGameObject != null )
{
go.transform.parent = Selection.activeGameObject.transform;
go.transform.position = Selection.activeGameObject.transform.position;
}
Selection.activeObject = go;
}
示例5: Create
static void Create()
{
GameObject go = new GameObject ( "PolyMesh", typeof ( MeshFilter ), typeof ( MeshRenderer ) );
PolyMesh polyMesh = go.AddComponent<PolyMesh> ();
CreateSquare ( polyMesh, 10 );
MeshRenderer renderer = go.GetOrCreateComponent<MeshRenderer> ();
Shader shader = Shader.Find ( "Sprites/Default" );
if ( shader != null )
{
Material material = new Material ( shader );
material.name = "PolyMesh Material";
material.SetColor ( "_Color", Color.gray );
// material.hideFlags = HideFlags.DontSave;
renderer.material = material;
}
if ( Selection.activeGameObject != null )
{
go.transform.parent = Selection.activeGameObject.transform;
go.transform.position = Selection.activeGameObject.transform.position;
}
Selection.activeObject = go;
}