> 다시 복습하는 차원에서, 다시 본다. 

- gameobject -> hero 빈 프리팹 만들어 놓고, 클론하는 방법인데 / 빈 hero 프리팹 없이 가능한건가? 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ingame : MonoBehaviour
{
    public Hero hero;
   
    public void Init(int characterId)
    {
        var data = DataManager.GetInstance().GetCharacterDataById(characterId);

        var path = string.Format("Prefabs/{0}", data.res_name);
        var prefab = Resources.Load(path) as GameObject;
        var modelGo = Instantiate(prefab);
        // 캐릭터 프리팹
        
        var heroPrefab = Resources.Load<GameObject>("Prefabs/hero");
        var heroGo = Instantiate<GameObject>(heroPrefab);
        this.hero = heroGo.AddComponent<Hero>();
        // 클론 상위 프리팹

        // 클론 hero 컴포넌트에 캐릭터 컴포넌트 붙이기 
        modelGo.transform.SetParent(this.hero.transform);

    }
    
    public static void log(object data) { Debug.Log(data); }
}

 

+ Recent posts