ソースコード
using UnityEngine;
<summary>
</summary>
public static class GameObjectUtils
{
<summary>
</summary>
public static GameObject Clone( GameObject go )
{
var clone = GameObject.Instantiate( go ) as GameObject;
clone.transform.parent = go.transform.parent;
clone.transform.localPosition = go.transform.localPosition;
clone.transform.localScale = go.transform.localScale;
return clone;
}
}
使い方
using UnityEngine;
public class NewMonoBehaviour : MonoBehaviour
{
private void Update()
{
if ( Input.GetKeyDown( KeyCode.Space ) )
{
GameObjectUtils.Clone( gameObject );
}
}
}
関連記事