Пример #1
0
    public GameObject addTower(TDTower.Type type, Vector3 pos)
    {
        GameObject tower = null;
        switch (type)
        {
            case TDTower.Type.eArrowTower:
                tower = (GameObject) Instantiate(m_prefabArrowTower, pos, Quaternion.identity);
                break;
            case TDTower.Type.eCanonTower:
                tower = (GameObject) Instantiate(m_prefabCanonTower, pos, Quaternion.identity);
                break;

        }
        return tower;
    }
Пример #2
0
    void OnMouseDown()
    {
        var naudhiz = Marker.GetUpgradeRunes().OfType <Naudhiz>().ToList();

        if (naudhiz.Any())
        {
            var marker = new GameObject("DefenseTower");
            marker.AddComponent <Algiz>();
            marker.transform.parent        = transform;
            marker.transform.localPosition = Vector3.zero;
            var tdTower = new TDTower(marker);
            tdTower.Tower.dmg *= 10;
            TDMap.Instance.Towers.Add(tdTower);
            foreach (var farm in TDMap.Instance.Farms)
            {
                farm.Explode();
            }
        }
    }
Пример #3
0
 private void Awake()
 {
     _instance = this;
 }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        TDWorld  world    = TDWorld.getWorld();
        TDPlayer tdPlayer = world.getTDPlayer();

        if (tdPlayer.health() <= 0)
        {
            Application.LoadLevel("GameOver");
        }

        if (Mode.eNone == m_mode)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(mouseRay, out hit))
            {
                if (hit.transform.gameObject.Equals(GameObject.Find("Terrain")))
                {
                    Vector3 pos = hit.point;
                    pos = TDWorld.getWorld().truncate3d(pos);
                    GameObject newTower = null;
                    if (TDGrid.CellState.eFree == world.positionState(pos))
                    {
                        switch (m_mode)
                        {
                        case Mode.eArcher:
                            if (!world.canTowerBeBuiltAt(pos))
                            {
                                break;
                            }
                            newTower = world.addTower(TDTower.Type.eArrowTower, pos);
                            break;

                        case Mode.eCanon:
                            if (!world.canTowerBeBuiltAt(pos))
                            {
                                break;
                            }
                            newTower = world.addTower(TDTower.Type.eCanonTower, pos);
                            break;

                        case Mode.eHeroPatrol:
                            TDHero tdHero = world.getTDHero();
                            tdHero.patrol(pos);
                            break;

                        default:
                            return;
                        }
                        if (newTower != null)
                        {
                            TDTower tdTower = world.getTDTower(newTower);
                            if (!tdPlayer.affords(tdTower.price()))
                            {
                                DestroyObject(newTower);
                                return;
                            }
                            tdPlayer.expense(tdTower.price());
                            TDWorld.getWorld().occupyPosition(pos, TDGrid.CellState.eBusy);
                        }
                    }
                }
            }
        }
    }