Ejemplo n.º 1
0
    //Spawneo de la torreta en una determinada base
    public void SpawnTurret(BaseTurret _base)
    {
        if (towers.Count > 0 && towers[0])
        {
            int goldTurret = 0;

            for (byte i = 0; i < properties.units.Length; ++i)
            {
                if (properties.units[i].name == "Turret")
                {
                    goldTurret = properties.units[i].cost;
                    break;
                }
            }

            //Revisa si puede permitirselo antes de spawnearlo
            if (CheckGold(goldTurret))
            {
                _base.SetTaken(true);

                GameObject turretTemp = (GameObject)Instantiate(turret, _base.gameObject.transform.position, Quaternion.identity);
                turretTemp.GetComponent <Turret>().ownPlayer = this;
                turretTemp.GetComponent <Turret>().Generate(team, "Turret");
                turretTemp.GetComponent <Turret>().SetBase(_base.gameObject.transform.GetComponent <BaseTurret>());
                gold -= turretTemp.GetComponent <Turret>().GetCost();

                playerUnits.Add(turretTemp.GetComponent <Unit>());
            }
        }
    }
 public void BigBerthaTurret()
 {
     HideTurrets();
     Turrets[6].SetActive(true);
     CurrentTurret = Turrets[6].GetComponent <BaseTurret>();
     SetText();
 }
 public void DroneTurret()
 {
     HideTurrets();
     Turrets[7].SetActive(true);
     CurrentTurret = Turrets[7].GetComponent <BaseTurret>();
     SetText();
 }
 public void ElectricTurret()
 {
     HideTurrets();
     Turrets[5].SetActive(true);
     CurrentTurret = Turrets[5].GetComponent <BaseTurret>();
     SetText();
 }
Ejemplo n.º 5
0
    public static int unknown = 2;                                      // we can add more types here if we had them

    void Start()
    {
        // if array is not empty we assign the first element as the default current turret type
        if (turrets.Length > 0)
        {
            Debug.Log("turret types = " + turrets.Length);
            currentTurret = turrets [0];
        }
    }
Ejemplo n.º 6
0
 protected virtual void OnTurretSpawned(BaseTurret turret)
 {
     if (TurretSpawned != null)
     {
         TurretSpawned(this, new TurretSpawnedEventArgs()
         {
             Life = (turret.Life).ToString()
         });
     }
 }
 void Awake()
 {
     health.SetValues();
     player        = FindObjectOfType <PlayerController>();
     turret        = FindObjectOfType <BaseTurret>();
     targetManager = FindObjectOfType <EnemyTargetManager>();
     agent         = GetComponent <NavMeshAgent>();
     myPos         = transform;
     agent.speed   = moveSpeed;
 }
Ejemplo n.º 8
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        // Gets reference to the original turret (before the upgrade)
        BaseTurret originalTurret = null;

        if (buildingSlot != null)
        {
            if (buildingSlot.GetBuildingOnSlot() != null)
            {
                originalTurret = buildingSlot.GetBuildingOnSlot().GetComponent <BaseTurret>();
            }
        }

        // Remove old healthbar (if valid)
        float hitpoints = MaxHitPoints;

        if (originalTurret != null)
        {
            hitpoints = originalTurret.GetHitPoints();
            if (originalTurret._HealthBar != null)
            {
                ObjectPooling.Despawn(originalTurret._HealthBar.gameObject);
            }
        }

        // Create weapon
        if (_TowerWeapon != null)
        {
            _TowerWeapon = ObjectPooling.Spawn(_TowerWeapon.gameObject).GetComponent <Weapon>();
        }

        // Start building process
        base.OnWheelSelect(buildingSlot);
        if (_ClonedWorldObject != null)
        {
            // Only proceed if there was a previous building & we're upgrading from that
            if (originalTurret != null)
            {
                // Update player ref
                _ClonedWorldObject.SetPlayer(originalTurret._Player);

                // Set the new base's building state object to be the currently active object
                _ClonedWorldObject.BuildingState = originalTurret.gameObject;
            }

            // Update attached building slot turret reference
            if (buildingSlot != null)
            {
                buildingSlot.SetBuildingOnSlot(_ClonedWorldObject.GetComponent <BaseTurret>());
            }

            // Reset turret's health
            _ClonedWorldObject.SetHitPoints(_ClonedWorldObject.MaxHitPoints);
        }
    }
Ejemplo n.º 9
0
 void Awake()
 {
     // we initialize some needed variables before the gaem start
     crystals = 0;
     credits  = 1000;
     //turret = turretFactory.GetComponent<TurretFactory> ().currentTurret;
     lvlUpPanelVisible = false;
     lvlUpBarActive    = false;
     // default initial turret (cannon turret)
     turret = turretFactory.GetComponent <TurretFactory> ().turrets [0];
     lvlUpBar.sliderValue = 0;
     UpdateScore();
 }
Ejemplo n.º 10
0
 void Awake()
 {
     health.SetValues();
     player              = FindObjectOfType <PlayerController>();
     turret              = FindObjectOfType <BaseTurret>();
     targetManager       = FindObjectOfType <EnemyTargetManager>();
     dayRef              = FindObjectOfType <DayNightCycle>();
     agent               = GetComponent <NavMeshAgent>();
     attackRadius        = GetComponent <CapsuleCollider>();
     agent.speed         = moveSpeed;
     attackRadius.radius = attackRange;
     attackRadius.height = attackRange;
 }
Ejemplo n.º 11
0
    public void UpgradeTurret()
    {
        GameObject newStructure = (GameObject)Instantiate(turretToUpgrade.updateObject, lastHitObj.transform.position, Quaternion.identity);

        levelMaster.cashCount -= turretToUpgrade.updateCost;
        Destroy(turretToUpgrade.gameObject);
        //newStructure.tag = "Obstacles";
        //newStructure.layer = 10;
        focusedPlain.myStructure = newStructure;
        turretToUpgrade          = null;
        CloseUpgradePanel();
        levelMaster.HUDUpdate();
    }
Ejemplo n.º 12
0
 public TurretSpawn(BaseTurret t)
     : base(PacketCmd.PKT_S2C_TurretSpawn)
 {
     buffer.Write((int)t.NetId);
     buffer.Write((byte)0x40);
     foreach (var b in Encoding.Default.GetBytes(t.Name))
     {
         buffer.Write((byte)b);
     }
     buffer.fill(0, 64 - t.Name.Length);
     buffer.Write((byte)0x0C);
     buffer.Write((byte)0x00);
     buffer.Write((byte)0x00);
     buffer.Write((byte)0x80);
     buffer.Write((byte)0x01);
 }
Ejemplo n.º 13
0
        protected override void Awake()
        {
            base.Awake();
            FirePoint = transform.Find(GameConstVal.FirePoint);
            if (FirePoint != null && m_FireEffect != null)
            {
                m_FireEffect.transform.SetParent(FirePoint, false);
                m_FireEffect.SetActive(true);
            }

            ItemItem weaponItem = Global.gApp.gGameData.GetItemDataByName(GameConstVal.WSFireTurret005);
            m_DtTime = weaponItem.dtime;

            InitDamage();
            m_FireTurret = GetComponentInParent<BaseTurret>();
            m_FireTurret.SetAtkRange(AtkRange);
        }
Ejemplo n.º 14
0
        public MovingTurretShot(Game game, BaseTurret emitter)
            : base(game)
        {
            // TODO: Construct any child components here
            ammo = emitter.CurrentAmmoType;

            maxSpeed     = ammo.baseSpeed * emitter.ammoSpeedModifier;
            acceleration = ammo.baseAcceleration * emitter.ammoAccelerationModifier;
            lifetime_ms  = ammo.baseLifetime_ms * emitter.ammoLifetimeModifier;
            damage       = ammo.baseDamage * emitter.ammoDamageModifier;

            position = emitter.EntrancePoint;
            center   = new Vector2(ammo.texture.Width / 2, ammo.texture.Height);

            rotation      = emitter.rotation;
            moveDirection = new Vector2((float)-Math.Sin(rotation), (float)-Math.Cos(rotation));
            // ToDo: Mit drehung des turrets syncen

            currentSpeed = 0.0f;
        }
Ejemplo n.º 15
0
 // when we select a turret from the GUI list we call this function
 public void OnSelectionChange(string selection)
 {
     // we get the current turret from the factory array of types
     if (selection == "Cannon Turret")
     {
         turret = turretFactory.GetComponent <TurretFactory> ().turrets [0];
     }
     else if (selection == "Laser Turret")
     {
         turret = turretFactory.GetComponent <TurretFactory> ().turrets [1];
     }
     else
     {
         turret = turretFactory.GetComponent <TurretFactory> ().turrets [0];
     }
     // we update the GUI
     turretCostLabel.text = "$ " + turret.deployCost;
     selectedTurret       = selection;
     EnoughCreditsToggle(turretCostLabel.gameObject);
 }
    void Awake()
    {
        health.SetValues();
        player              = FindObjectOfType <PlayerController>();
        fire                = FindObjectOfType <FireManager>();
        turret              = FindObjectOfType <BaseTurret>();
        wall                = FindObjectOfType <Durability>();
        targetManager       = FindObjectOfType <EnemyTargetManager>();
        dayRef              = FindObjectOfType <DayNightCycle>();
        agent               = GetComponent <NavMeshAgent>();
        attackRadius        = GetComponent <CapsuleCollider>();
        agent.speed         = moveSpeed;
        attackRadius.radius = attackRange;
        attackRadius.height = attackRange;

        foreach (GameObject waypoint in GameObject.FindGameObjectsWithTag("Waypoint"))
        {
            wayPoints.Add(waypoint);
        }

        chosenWayPoint = Random.Range(0, wayPoints.Count);

        targetWayPoint = wayPoints[chosenWayPoint].transform.position;
    }
Ejemplo n.º 17
0
 public void DeSelectTurret()
 {
     CurrentTurret.Selected = false;
     CurrentTurret          = null;
 }
Ejemplo n.º 18
0
 public void Spawn(BaseTurret turret)
 {
     OnTurretSpawned(turret);
 }
Ejemplo n.º 19
0
    void Awake()
    {
        cannon = GameObject.Find("cannon").GetComponent<AudioSource>();
        missile = GameObject.Find("rocket").GetComponent<AudioSource>();
        choice = PlayerPrefs.GetInt("Select");
        if (choice == 1)
        {
            defaultTurret = TurretChoice.Tur1;
        }
        if (choice == 0)
        {
            defaultTurret = TurretChoice.Tur2;
        }
        CrosshairTransform = moveCrosshair.Instance().transform;
        if (!CrosshairTransform) 
            Debug.Log("MOVECROSSHAIR NOT FOUND");
        m_Rigidbody = GetComponent<Rigidbody>();

        if (BT1 == null)
            Debug.Log("First Turret Missing");
        if (BT2 == null)
            Debug.Log("Second Turret Missing");
        if (BT3 == null)
            Debug.Log("Third Turret Missing");
        m_Speed = Speed;
        if (BT1 != null)
        {
            if (defaultTurret == TurretChoice.Tur1)
            {
                audioChoice = 0;
                activeTurret = BT1;
            }

        }
        if (BT2 != null)
        {
            if (defaultTurret == TurretChoice.Tur2)
            {
                audioChoice = 1;
                activeTurret = BT2;
            }

        }
        if (BT3 != null)
        {
            if (defaultTurret == TurretChoice.Tur3)
                activeTurret = BT3;
        }

        if (GameObject.Find("BlueCross") == null)
            Debug.LogError("No Crosshair");
        startTankLocation = this.transform;
    }
Ejemplo n.º 20
0
    //Frame Rate check for tank
    void FixedUpdate()
    {
        if (BT1 != null)
        {
            if (defaultTurret == TurretChoice.Tur1)
            {
                this.GetComponentInChildren<Transform>().GetChild(0).gameObject.SetActive(false);
                activeTurret = BT1;
            }

        }
        if (BT2 != null)
        {
            if (defaultTurret == TurretChoice.Tur2)
            {
                this.GetComponentInChildren<Transform>().GetChild(2).gameObject.SetActive(false);
                activeTurret = BT2;
            }

        }
        if (BT3 != null)
        {
            if (defaultTurret == TurretChoice.Tur3)
                activeTurret = BT3;
        }
        //move tank to crosshair
        levelPosition = CrosshairTransform.GetComponent<moveCrosshair>().levelPosition;
        {
            Move(levelPosition);
            Turn(levelPosition);
        }
        
        //Fire the turret
        if (Input.GetMouseButtonDown(0))
        {
            FireTurret();
        }
        
    }
Ejemplo n.º 21
0
 public void FindAllies(bool Sold)
 {
     Hit = Physics2D.OverlapCircleAll(transform.position, Radius + 0.1f);
     foreach (Collider2D enemy in Hit)
     {
         if (enemy.tag == "Turret" && !enemy.GetComponent <Radar>())
         {
             BaseTurret AffectedTurret = enemy.GetComponent <BaseTurret>();
             if (!Sold)
             {
                 if (!AffectedTurret.RadarT1LvlUpgrade && Level1UpgradeRank >= 1)
                 {
                     AffectedTurret.RadarT1LvlUpgrade = true;
                 }
                 if (!AffectedTurret.RadarT2LvlUpgrade && Level1UpgradeRank >= 2)
                 {
                     AffectedTurret.RadarT2LvlUpgrade = true;
                 }
                 if (!AffectedTurret.RadarT3LvlUpgrade && Level1UpgradeRank >= 3)
                 {
                     AffectedTurret.RadarT3LvlUpgrade = true;
                 }
                 if (!AffectedTurret.RadarT4LvlUpgrade && Level2UpgradeRank >= 1)
                 {
                     AffectedTurret.RadarT4LvlUpgrade = true;
                 }
                 if (!AffectedTurret.RadarT5LvlUpgrade && Level2UpgradeRank >= 2)
                 {
                     AffectedTurret.RadarT5LvlUpgrade = true;
                 }
                 if (!AffectedTurret.RadarT6LvlUpgrade && Level2UpgradeRank >= 3)
                 {
                     AffectedTurret.RadarT6LvlUpgrade = true;
                 }
             }
             else
             {
                 if (AffectedTurret.RadarT1LvlUpgrade)
                 {
                     AffectedTurret.RadarT1LvlUpgrade = false;
                 }
                 if (AffectedTurret.RadarT1LvlUpgrade)
                 {
                     AffectedTurret.RadarT2LvlUpgrade = false;
                 }
                 if (AffectedTurret.RadarT3LvlUpgrade)
                 {
                     AffectedTurret.RadarT3LvlUpgrade = false;
                 }
                 if (AffectedTurret.RadarT4LvlUpgrade)
                 {
                     AffectedTurret.RadarT4LvlUpgrade = false;
                 }
                 if (AffectedTurret.RadarT5LvlUpgrade)
                 {
                     AffectedTurret.RadarT5LvlUpgrade = false;
                 }
                 if (AffectedTurret.RadarT6LvlUpgrade)
                 {
                     AffectedTurret.RadarT6LvlUpgrade = false;
                 }
             }
         }
     }
 }
 //Establece la base a la que pertenece
 public void SetBase(BaseTurret _baseTurret)
 {
     baseTurret = _baseTurret;
 }
Ejemplo n.º 23
0
    void Update()
    {
        // on deploy mode we cast rays to the grid layer (cells)
        if (deployModeOn)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            // if we hit a cell (they are the only ones that lay in the gridlayer)
            if (Physics.Raycast(ray, out hit, 1000, gridLayer))
            {
                // if we had hit something before we unhighlight it (restore it to normal)
                if (lastHitCell)
                {
                    TagNeighboringCells("Cell_Empty");
                }

                // if we hadnt hit anything we get the cell where the ray hit
                // and highlight it
                lastHitCell = hit.collider.gameObject;
                TagNeighboringCells("Cell_Highlight");
                Debug.Log("Hit cell = " + lastHitCell);
                // if we hit nothing (i.e. outside of grid)
            }
            else
            {
                // if we had hit something before we unmark that cell and assign null to the last hit
                if (lastHitCell)
                {
                    TagNeighboringCells("Cell_Empty");
                    lastHitCell = null;
                }
            }

            // if we left click on a cell and the upgrade panel is hidden
            if (Input.GetMouseButtonDown(0) && lastHitCell && !lvlUpPanelVisible)
            {
                // if we are over an empty cell we place a new one if possible
                if (lastHitCell.tag == "Cell_Empty")
                {
                    // get the dimensions of the current turret
                    Vector2 turretCellSize = turret.size;
                    // get the neighboring cells
                    List <GameObject> placementCells = ground.GetNeighborhood(turretCellSize, lastHitCell);
                    // if every neighbor is tagged "Cell_Empty" (i.e. valid deploy) and we have enough money
                    if (ValidDeploy(placementCells, turretCellSize) && credits >= turret.deployCost)
                    {
                        // get the mid point of those cells
                        Vector3 turretPos = GetCellsMidPoint(placementCells);
                        // place a new turret there
                        BaseTurret placedTurret = (BaseTurret)Instantiate(turret, turretPos, Quaternion.identity);
                        // mark them as occupied
                        TagNeighboringCells("Cell_Occupied");
                        // we need to add the same turret instance to every cell in the neighborhood
                        // to retrieve it later for the upgrade
                        foreach (GameObject cell in placementCells)
                        {
                            cell.GetComponent <Cell> ().cellTurret = placedTurret;
                        }
                        // update money
                        credits -= turret.deployCost;
                        UpdateScore();
                    }
                    // if we are over an occupied cell	we level up that turret if possible
                }
                else if (lastHitCell.tag == "Cell_Occupied" && !lvlUpBarActive)
                {
                    // obtain the turret on those cells to upgrade it
                    turretToLvlUp = lastHitCell.GetComponent <Cell> ().cellTurret.GetComponent <BaseTurret> ();
                    Debug.Log("Turret to level up = " + turretToLvlUp);
                    // show level up panel
                    ShowLvlUpPanel();
                }
            }
        }
    }
Ejemplo n.º 24
0
 public ReplicationAiTurret(BaseTurret owner) : base(owner)
 {
 }
Ejemplo n.º 25
0
 public void UpgradeTurret()
 {
     GameObject newStructure = (GameObject)Instantiate (turretToUpgrade.updateObject, lastHitObj.transform.position, Quaternion.identity);
     levelMaster.cashCount -= turretToUpgrade.updateCost;
     Destroy (turretToUpgrade.gameObject);
     //newStructure.tag = "Obstacles";
     //newStructure.layer = 10;
     focusedPlain.myStructure = newStructure;
     turretToUpgrade = null;
     CloseUpgradePanel ();
     levelMaster.HUDUpdate();
 }
Ejemplo n.º 26
0
 public TurretSessionData(Camera newTrackingCamera, BaseTurret newBaseTurret)
 {
     trackingCamera = newTrackingCamera;
     baseTurret     = newBaseTurret;
 }
    public void Attack()
    {
        attackRay.origin    = transform.position - new Vector3(0f, 0.5f, 0f);
        attackRay.direction = transform.forward;

        if (targetsInRange[0] == true && health.CurValue > 0)
        {
            if (Physics.Raycast(attackRay, out attackHit))
            {
                attackTimer += Time.deltaTime;

                if (attackTimer >= attackSpeed)
                {
                    if (player.health.CurValue > 0)
                    {
                        player.TakeDamage(attackDamage, attackHit.point);
                    }
                    attackTimer = 0;
                }
            }
        }

        if (targetsInRange[1] == true && health.CurValue > 0)
        {
            if (Physics.Raycast(attackRay, out attackHit))
            {
                attackTimer += Time.deltaTime;

                if (attackTimer >= attackSpeed)
                {
                    if (fire.health.CurValue > 0)
                    {
                        fire.TakeDamage(attackDamage, attackHit.point);
                    }
                    attackTimer = 0;
                }
            }
        }

        if (targetsInRange[2] == true && health.CurValue > 0)
        {
            if (Physics.Raycast(attackRay, out attackHit))
            {
                BaseTurret turretHealth = attackHit.collider.GetComponent <BaseTurret>();
                attackTimer += Time.deltaTime;

                if (attackTimer >= attackSpeed)
                {
                    if (turretHealth.health.CurValue > 0)
                    {
                        turretHealth.TakeDamage(attackDamage, attackHit.point);
                    }
                    attackTimer = 0;
                }
            }
        }

        if (targetsInRange[3] == true && health.CurValue > 0)
        {
            if (Physics.Raycast(attackRay, out attackHit))
            {
                Durability wallHealth = attackHit.collider.GetComponent <Durability>();
                attackTimer += Time.deltaTime;

                if (attackTimer >= attackSpeed)
                {
                    if (wallHealth != null)
                    {
                        wallHealth.TakeDamage(attackDamage, attackHit.point);
                    }
                    attackTimer = 0;
                }
            }
        }
    }
Ejemplo n.º 28
0
    // Update is called once per frame
    void Update()
    {
        ///

        ///
        if (isBuildPanel && !upgradePanelOpen)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 1000, placementLayer))
            {
                if (lastHitObj)
                {
                    lastHitObj.renderer.material = originalMat;
                }

                lastHitObj  = hit.collider.gameObject;
                originalMat = lastHitObj.renderer.material;
                lastHitObj.renderer.material = hoverMat;
            }
            else
            {
                if (lastHitObj)
                {
                    lastHitObj.renderer.material = originalMat;
                    lastHitObj = null;
                }
            }
            if (Input.GetMouseButtonDown(0) && lastHitObj)
            {
                focusedPlain = (PlacementPlain)lastHitObj.GetComponent("PlacementPlain");
                //Debug.Log("Click!");

                if (lastHitObj.tag == "Placement_Open" && levelMaster.WeaponPrices[structureIndex] <= levelMaster.cashCount &&
                    levelMaster.WeaponAvailibility[structureIndex] <= levelMaster.waveLevel)
                {
                    //Debug.Log("Placement Open");
                    Vector3 vec3;

                    // fixing pivot point mistake
                    if (structureIndex == 1)
                    {
                        vec3 = new Vector3(lastHitObj.transform.position.x, lastHitObj.transform.position.y + 0.30f, lastHitObj.transform.position.z);                      //if launcher move little bit up
                    }
                    else
                    {
                        vec3 = new Vector3(lastHitObj.transform.position.x, lastHitObj.transform.position.y, lastHitObj.transform.position.z);
                    }



                    GameObject newStructure = (GameObject)Instantiate(allStructures[structureIndex], lastHitObj.transform.position, Quaternion.identity);
                    newStructure.transform.position = vec3;

                    newStructure.transform.localEulerAngles = new Vector3(newStructure.transform.localEulerAngles.x, Random.Range(0, 360), newStructure.transform.localEulerAngles.z);
                    newStructure.tag = "Obstacles";
                    //newStructure.layer = 10;
                    lastHitObj.tag           = "Placement_Taken";
                    focusedPlain.myStructure = newStructure;

                    levelMaster.cashCount -= levelMaster.WeaponPrices[structureIndex];
                    levelMaster.HUDUpdate();


                    astar.Scan();
                    Debug.Log("Scan");
                    foreach (GameObject tnk in GameObject.FindGameObjectsWithTag("Ground Enemy"))
                    {
                        Tank tnkScript = (Tank)tnk.GetComponent("Tank");
                        tnkScript.FindNewPath();
                    }
                    //UpdateGUI();
                }
/*UPGRADE*/ else if (lastHitObj.tag != "Placement_Open")
                {
                    //upgrade turret

                    turretToUpgrade = (BaseTurret)focusedPlain.myStructure.GetComponent("BaseTurret");
                    if (turretToUpgrade.updateObject)
                    {
                        upgradeCost      = turretToUpgrade.updateCost;
                        upgradeText.text = "Upgrade to\n " + turretToUpgrade.name + " $" + turretToUpgrade.updateCost + "?";
                        CheckUpgradeAvailible();
                        upgradePanelTweener.enabled = true;
                        upgradePanelTweener.Play(true);
                        upgradePanelOpen = true;
                    }

                    //Debug.Log ("upgrade panel");
                }
            }
        }         //isBuildPanel
    }
Ejemplo n.º 29
0
    // Update is called once per frame
    void Update()
    {
        ///

        ///
        if (isBuildPanel && !upgradePanelOpen) {
                        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                        RaycastHit hit;

                        if (Physics.Raycast (ray, out hit, 1000, placementLayer)) {
                                if (lastHitObj) {
                                        lastHitObj.renderer.material = originalMat;
                                }

                                lastHitObj = hit.collider.gameObject;
                                originalMat = lastHitObj.renderer.material;
                                lastHitObj.renderer.material = hoverMat;
                        } else {
                                if (lastHitObj) {
                                        lastHitObj.renderer.material = originalMat;
                                        lastHitObj = null;
                                }
                        }
            if (Input.GetMouseButtonDown(0) && lastHitObj ) {
                focusedPlain = (PlacementPlain)lastHitObj.GetComponent("PlacementPlain");
                //Debug.Log("Click!");

                    if (lastHitObj.tag == "Placement_Open" && levelMaster.WeaponPrices[structureIndex]<=levelMaster.cashCount &&
                    levelMaster.WeaponAvailibility[structureIndex] <= levelMaster.waveLevel)
                {
                    //Debug.Log("Placement Open");
                    Vector3 vec3;

                    // fixing pivot point mistake
                    if (structureIndex == 1) {
                        vec3 = new Vector3(lastHitObj.transform.position.x, lastHitObj.transform.position.y+0.30f,lastHitObj.transform.position.z); //if launcher move little bit up
                    }
                    else {vec3 = new Vector3(lastHitObj.transform.position.x, lastHitObj.transform.position.y,lastHitObj.transform.position.z);}

                    GameObject newStructure = (GameObject)Instantiate(allStructures[structureIndex], lastHitObj.transform.position,Quaternion.identity);
                    newStructure.transform.position = vec3;

                    newStructure.transform.localEulerAngles = new Vector3(newStructure.transform.localEulerAngles.x, Random.Range(0,360), newStructure.transform.localEulerAngles.z);
                    newStructure.tag="Obstacles";
                    //newStructure.layer = 10;
                    lastHitObj.tag = "Placement_Taken";
                    focusedPlain.myStructure = newStructure;

                    levelMaster.cashCount -= levelMaster.WeaponPrices[structureIndex];
                    levelMaster.HUDUpdate();

                    astar.Scan();
                    Debug.Log("Scan");
                    foreach (GameObject tnk in GameObject.FindGameObjectsWithTag("Ground Enemy")) {
                        Tank tnkScript = (Tank)tnk.GetComponent("Tank");
                        tnkScript.FindNewPath();

                    }
                    //UpdateGUI();
                }
        /*UPGRADE*/				else if (lastHitObj.tag != "Placement_Open") {
                    //upgrade turret

                    turretToUpgrade = (BaseTurret) focusedPlain.myStructure.GetComponent("BaseTurret");
                    if (turretToUpgrade.updateObject)
                    {
                            upgradeCost = turretToUpgrade.updateCost;
                            upgradeText.text = "Upgrade to\n "+turretToUpgrade.name+" $"+turretToUpgrade.updateCost+"?";
                            CheckUpgradeAvailible();
                            upgradePanelTweener.enabled = true;
                            upgradePanelTweener.Play(true);
                            upgradePanelOpen = true;
                    }

                    //Debug.Log ("upgrade panel");
                }

            }
        } //isBuildPanel
    }