Exemplo n.º 1
0
    Character CreateCharacter(string fileName, string spriteName)
    {
        string     filePath            = "Prefabs/CharacterFrame/Character";
        GameObject characterPrefabs    = Resources.Load <GameObject>(filePath);
        GameObject characterGameObject = GameObject.Instantiate(characterPrefabs);

        characterGameObject.transform.SetParent(_tileMap.transform);
        characterGameObject.transform.localPosition = Vector3.zero;

        Character character = characterGameObject.GetComponent <Player>();

        switch (fileName)
        {
        case "Player":
            character = characterGameObject.AddComponent <Player>();
            break;

        case "Monster":
            character = characterGameObject.AddComponent <Monster>();
            break;
        }

        character.Init(spriteName);

        Slider hpGuage = GameUI.CreateHPSlider();

        character.LinkHPGuage(hpGuage);

        Slider coolDownGuage = GameUI.CreateCoolDownSlider();

        character.LinkCoolDownGuage(coolDownGuage);

        return(character);
    }
Exemplo n.º 2
0
    Character CreateCharacter(string fileName, string resourceName)
    {
        //캐릭터 생성
        string     filePath       = "Prefabs/CharacterFrame/Character";
        GameObject charPrefabs    = Resources.Load <GameObject>(filePath);
        GameObject charGameObject = GameObject.Instantiate(charPrefabs);

        charGameObject.transform.SetParent(_tileMap.transform);
        charGameObject.transform.localPosition = Vector3.zero;
        charGameObject.AddComponent <Rigidbody2D>().bodyType       = RigidbodyType2D.Kinematic;
        charGameObject.AddComponent <CircleCollider2D>().radius    = 0.1f;
        charGameObject.GetComponent <CircleCollider2D>().isTrigger = true;
        Character character = charGameObject.GetComponent <Player>();

        switch (fileName)
        {
        case "Player":
            charGameObject.name = "Player";
            character           = charGameObject.AddComponent <Player>();
            break;

        case "Monster":
            charGameObject.name = "Monster";
            character           = charGameObject.AddComponent <Monster>();
            break;
        }
        character.Init(resourceName);

        Slider hpGuage = GameUI.CreateHPSlider();

        character.LinkHPGuage(hpGuage);

        Slider cooltimeGuage = GameUI.CreateCooltimeSlider();

        character.LinkActionCooltimeGuage(cooltimeGuage);

        Text textLevel = GameUI.CreateLevelText();

        character.LinkTextLevel(textLevel);

        Button atkButton = GameUI.CreateAtkButton();

        character.LinkAtkButton(atkButton);

        Button waitButton = GameUI.CreateWaitButton();

        character.LinkWaitButton(waitButton);

        character.SetCanvasLayer(eTileLayer.UI);
        return(character);
    }