Пример #1
0
    //when the mouse is click on the the cube object
    void OnMouseDown()
    {
        if (levelDesigner.GetSelectedType() == levelDesigner.GetPlayer())
        {
            if (levelDesigner.GetNumOfPlayerBlock() < 4)
            {
                if (levelDesigner.GetBlockType(Int32.Parse(gameObject.name.Substring(3, 1)), Int32.Parse(gameObject.name.Substring(1, 1))) != levelDesigner.GetPlayer())
                {
                    levelDesigner.SetNumOfPlayerBlock(levelDesigner.GetNumOfPlayerBlock() + 1); //increase the number of block that is player state
                }
                levelDesigner.SetBlockType(Int32.Parse(gameObject.name.Substring(3, 1)),        //get the number of row
                                           Int32.Parse(gameObject.name.Substring(1, 1)),        //get the number of coloumn
                                           levelDesigner.GetSelectedType());                    //get the current selectedType
            }
        }
        else if (levelDesigner.GetBlockType(Int32.Parse(gameObject.name.Substring(3, 1)), Int32.Parse(gameObject.name.Substring(1, 1))) == levelDesigner.GetPlayer())
        {
            levelDesigner.SetNumOfPlayerBlock(levelDesigner.GetNumOfPlayerBlock() - 1); //decrease the number of block that is player state
            //change the value in the 2d array that save the state of each block
            levelDesigner.SetBlockType(Int32.Parse(gameObject.name.Substring(3, 1)),    //get the number of row
                                       Int32.Parse(gameObject.name.Substring(1, 1)),    //get the number of coloumn
                                       levelDesigner.GetSelectedType());                //get the current selectedType
        }
        else
        {
            //change the value in the 2d array that save the state of each block
            levelDesigner.SetBlockType(Int32.Parse(gameObject.name.Substring(3, 1)), //get the number of row
                                       Int32.Parse(gameObject.name.Substring(1, 1)), //get the number of coloumn
                                       levelDesigner.GetSelectedType());             //get the current selectedType
        }

        Debug.Log("click " + gameObject.name);
        Debug.Log("R" + gameObject.name.Substring(3, 1) + "C" + gameObject.name.Substring(1, 1));
    }