예제 #1
0
    public void CreateGod(Tile[,] tiles, bool isPlayer, string godName, int MaxMovement, int attackRange, int attackStregnth, int health)
    {
        // Create and assign variables to God unit
        GameObject GodGo = Instantiate(God);
        God        g     = new God(godName);

        GodGo.GetComponent <UnitObjectScript>().setUnit(g);
        g.assignGameObject(GodGo);

        //TODO, don't know exactly how we're handling this
        g.setWorshiperCount(0);
        g.setMorale(1);


        g.MaxMovement    = MaxMovement;
        g.attackRange    = attackRange;
        g.AttackStrength = attackStregnth;
        g.WorshiperCount = health;

        if (isPlayer)
        {
            BoardMan.playerUnits.Add(g);
            g.isPlayer = true;
            g.setAbilities(gameInfo.PlayerFaction.Abilities);
            g.MoveTo(new Vector2(-1, -1), tiles);
            g.unitGameObject().transform.position = new Vector3(0, MapMan.godFloatHeight, MapMan.tiles.GetLength(1) / 2);

            // Load the 3D model
            GameObject godModel;

            try
            {
                godModel = Instantiate(Resources.Load("Gods/" + gameInfo.PlayerFaction.Type.ToString(), typeof(GameObject))) as GameObject;
            }
            catch (Exception e)
            {
                godModel = Instantiate(Resources.Load("Gods/Mushrooms", typeof(GameObject))) as GameObject;
            }

            godModel.transform.SetParent(g.unitGameObject().transform);
            godModel.transform.position = new Vector3(GodGo.transform.position.x, GodGo.transform.position.y + godModel.GetComponent <GroundOffset>().groundOffset,
                                                      GodGo.transform.position.z + godModel.GetComponent <GroundOffset>().zOffset);

            GodGo.GetComponent <CapsuleCollider>().center = new Vector3(0, godModel.GetComponent <GroundOffset>().colliderCenter, 0);

            GodGo.GetComponent <CapsuleCollider>().height = godModel.GetComponent <GroundOffset>().colliderHeight;

            //Face east
            g.turnToFace(3);

            g.AllowAct();
        }
        else
        {
            BoardMan.enemyUnits.Add(g);
            g.EndAct();
            g.isPlayer = false;
            g.setAbilities(gameInfo.EnemyFaction.Abilities);
            g.MoveTo(new Vector2(-1, -1), tiles);
            g.unitGameObject().transform.position = new Vector3(MapMan.tiles.GetLength(0), MapMan.godFloatHeight, MapMan.tiles.GetLength(1) / 2);

            GameObject godModel;

            try
            {
                godModel = Instantiate(Resources.Load("Gods/" + gameInfo.EnemyFaction.Type.ToString(), typeof(GameObject))) as GameObject;
            }
            catch (Exception e)
            {
                godModel = Instantiate(Resources.Load("Gods/Mushrooms", typeof(GameObject))) as GameObject;
            }

            godModel.transform.SetParent(g.unitGameObject().transform);
            godModel.transform.position = new Vector3(GodGo.transform.position.x, GodGo.transform.position.y + godModel.GetComponent <GroundOffset>().groundOffset,
                                                      GodGo.transform.position.z + godModel.GetComponent <GroundOffset>().zOffset);

            GodGo.GetComponent <CapsuleCollider>().center = new Vector3(0, godModel.GetComponent <GroundOffset>().colliderCenter, 0);

            GodGo.GetComponent <CapsuleCollider>().height = godModel.GetComponent <GroundOffset>().colliderHeight;

            //Face west
            g.turnToFace(1);
        }
    }