[MenuItem("Window/UnitZ/Component/Character/Player")]
static void CreatePlayer ()
{
if (Selection.activeGameObject != null) {
if (Selection.activeGameObject.GetComponent<Animator> () == null) {
Debug.LogWarning ("The model must have 'Animator' component");
}
Selection.activeGameObject.AddComponent<PlayerCharacter> ();
Object prefab = AssetDatabase.LoadAssetAtPath ("Assets/UnitZ/Editor/Prefabs/FPScamera.prefab", typeof(GameObject));
GameObject clone = Instantiate (prefab, Vector3.zero, Quaternion.identity) as GameObject;
clone.transform.SetParent (Selection.activeGameObject.transform);
clone.transform.position = Vector3.zero;
}
}
【Unity编辑器】Case:给选中对象添加组件,实例化对象
最新推荐文章于 2021-04-21 17:59:00 发布