public void OnChangePowerClick()
 {
     m.Play_Click();
     if (m.powerChrage >= 50)
     {
         m.UpdatePowerCharge(powerPlate, -50);
     }
     else
     {
         return;
     }
     currentPower = Powers.Change;
     powerPanel.GetComponent <Animator> ().SetBool("show", false);
     ChangePowerHelper.SetActive(true);
 }
    public void CancleChangePower()
    {
        m.Play_Click();
        currentPower = Powers.None;

        ChangePowerHelper.SetActive(false);
        if (switchObjects.Count > 0)
        {
            ChangePowerPanel.GetComponent <Animator> ().SetBool("show", false);
        }

        temp_switch_int = 0;
        switchObjects.Clear();

        m.UpdatePowerCharge(powerPlate, 50);

        OnPowerPanelClose();
    }
    // this function is called everytime user points down on any of the boxes
    public void OnAnyDotDown(GameObject hit)
    {
        if (currentPower == Powers.Destroy)
        {
            DestroyKey(hit);
            currentPower = Powers.None;
            OnPowerPanelClose();
            DestroPowerHelper.SetActive(false);
            Invoke("UpdateNames", 0.5f);
            return;
        }
        else if (currentPower == Powers.Change && temp_switch_int == 0)
        {
            temp_switch_int = 1;
            switchObjects.Add(hit);
            ChangePowerPanel.GetComponent <Animator> ().SetBool("show", true);
            ChangePowerHelper.SetActive(false);
            return;
        }
        else if (currentPower == Powers.Switch && temp_switch_int < 2)
        {
            hit.GetComponent <Animator> ().SetBool("inc", true);
            temp_switch_int++;
            switchObjects.Add(hit);

            if (temp_switch_int == 2)
            {
                SetKinematic(true);

                Vector3 v1 = switchObjects [0].transform.position;
                Vector3 v2 = switchObjects [1].transform.position;

                string s1 = switchObjects [0].name;
                string s2 = switchObjects [1].name;

                switchObjects [0].name = s2;
                switchObjects [1].name = s1;

//				switchObjects [0].GetComponent<Rigidbody2D> ().isKinematic = true;
//				switchObjects [1].GetComponent<Rigidbody2D> ().isKinematic = true;


                switchObjects [0].GetComponent <DotScript> ().MoveTo(v2);
                switchObjects [1].GetComponent <DotScript> ().MoveTo(v1);

                SwitchPowerHelper.SetActive(false);
            }
            return;
        }

        if (isPaused)
        {
            return;
        }


        if (!touchStarted)
        {
            m.Play_DotSelect();

            touchStarted = true;
            currentChain.Add(hit);
            hit.GetComponent <DotScript> ().selected = true;
            hit.transform.GetChild(0).gameObject.SetActive(true);
            MainLine.transform.position = hit.transform.position;
            MainLine.positionCount      = currentChain.Count;
            MainLine.SetPosition(currentChain.Count - 1, hit.transform.position);
        }
        else
        {
            if (currentChain.Count > 2 && hit == currentChain [currentChain.Count - 2])
            {
                GameObject wo = currentChain [currentChain.Count - 1];
                currentChain.Remove(wo);
                wo.transform.GetChild(0).gameObject.SetActive(false);
                wo.GetComponent <DotScript> ().selected = false;
                MainLine.positionCount -= 1;
                wo.GetComponent <DotScript> ().ChildImage.gameObject.SetActive(false);
            }
            else if (Neighbour(hit.name) && hit.GetComponent <DotScript>().currentvalue == currentChain[0].GetComponent <DotScript>().currentvalue&& !hit.GetComponent <DotScript>().selected)
            {
                m.Play_DotSelect();
                currentChain.Add(hit);
                hit.transform.GetChild(0).gameObject.SetActive(true);
                hit.GetComponent <DotScript> ().selected = true;
                MainLine.positionCount = currentChain.Count;
                MainLine.SetPosition(currentChain.Count - 1, hit.transform.position);
            }
        }
    }