Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (this._defenseInstanceToAdd != null || this._deleting)
            {
                MapScript mapScript = MapScript.sharedInstance();
                if (mapScript.selectionIsVisible())
                {
                    if (this._defenseInstanceToAdd != null)
                    {
                        DefenseScript def = this._defenseInstanceToAdd.GetComponent <DefenseScript> ();
                        if (PlayerScript.sharedInstance().getMoney() >= def.price)
                        {
                            Position selectionPos = mapScript.getSelectionPosition();
                            if (mapScript.tryToBlockPosition(selectionPos))
                            {
                                Vector3 position = mapScript.getPointForMapCoordinates(selectionPos);
                                this._defenseInstanceToAdd.transform.position = position;
                                DefenseScript defenseScript = this._defenseInstanceToAdd.GetComponent <DefenseScript> ();
                                defenseScript.setPosition(selectionPos);
                                defenseScript.setUsable(true);
                                defenseScript.showRadius(false);
                                this._allDefenses.Add(defenseScript);
                                BroadcastMessage("defenseWasAdded", defenseScript);

                                this._defenseInstanceToAdd = (GameObject)Instantiate(this._defenseInstanceToAdd, MapScript.sharedInstance().hiddenPosition(), Quaternion.identity);
                            }
                        }
                    }
                    else
                    {
                        DefenseScript def;
                        if (this.anyDefenseAtPosition(mapScript.getSelectionPosition(), out def))
                        {
                            BroadcastMessage("defenseWasRemoved", def);
                            this._allDefenses.Remove(def);
                            GameObject defGO = def.gameObject;
                            Destroy(defGO);
                        }
                    }
                }
            }
        }

        if (this._defenseInstanceToAdd != null)
        {
            MapScript     mapScript = MapScript.sharedInstance();
            DefenseScript ds        = this._defenseInstanceToAdd.GetComponent <DefenseScript> ();
            if (mapScript.selectionIsVisible())
            {
                Position selectionPos = mapScript.getSelectionPosition();
                ds.setPosition(selectionPos);
            }
            else
            {
                ds.setPosition(new Position(-1, -1));
            }
        }
    }