Example #1
0
    public void SpawnCharacter(string path, string name, int tileX, int tileY, eCharacter chessCharacterType, ChessCharacter.eCharacterType characterType)
    {
        GameObject character = Instantiate(Resources.Load(path)) as GameObject;

        character.name = name;
        ChessCharacter cCharacter = character.GetComponent <ChessCharacter>();

        cCharacter.SetTilePosition(new Vector3Int(tileX, tileY, 0));
        cCharacter.SetCharacterType(characterType);
        cCharacter.SetChessCharacterType(chessCharacterType);
        Debug.Log("Spawn in GameManager");
        character.transform.SetParent(tilemap.transform);

        ChessTile chessTile = tilemap.GetTile <ChessTile>(new Vector3Int(tileX, tileY, 0));

        if (chessTile != null)
        {
            chessTile.gameObject = character;
        }

        GameObject    canvas     = GameObject.Find("Canvas");
        RectTransform canvasRect = canvas.GetComponent <RectTransform>();

        //slider transform 세팅
        GameObject sliderObject = Instantiate(Resources.Load("Prefabs/UI/HpBar"), hpbarPanel.transform) as GameObject;
        //sliderObject.transform.SetParent(canvas.transform, false);

        Slider slider = sliderObject.GetComponent <Slider>();

        cCharacter.SetHpBar(slider);
    }
Example #2
0
    private bool BuyWaitCharacter(string path, string name, eCharacter characterType)
    {
        int waitPositionX = 0;

        while (waitPositionX < 8)
        {
            ChessTile chessTile = tilemap.GetTile <ChessTile>(new Vector3Int(waitPositionX, -1, 0));
            if (chessTile != null)
            {
                if (chessTile.gameObject == null)
                {
                    GameObject character = Instantiate(Resources.Load(path)) as GameObject;
                    character.name = name;
                    ChessCharacter cCharacter = character.GetComponent <ChessWaitCharacter>();
                    character.transform.SetParent(tilemap.transform);

                    cCharacter.SetTilePosition(new Vector3Int(waitPositionX, -1, 0));
                    cCharacter.SetCharacterType(ChessCharacter.eCharacterType.WAIT);
                    cCharacter.SetChessCharacterType(characterType);
                    chessTile.gameObject = character;
                    return(true);
                }
            }
            waitPositionX++;
        }
        return(false);
    }