Exemplo n.º 1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, float.MaxValue, layerMask))
        {
            if (hit.collider.tag == "Chip")
            {
                Chip hitChip = hit.collider.GetComponent <Chip>();
                if (hitChip.idPlayer == idThisPlayer & !hitChip.isOnFinalCell)
                {
                    if (thisSelectedChip != null)
                    {
                        thisSelectedChip.ChipUnSelected();
                        thisSelectedChip = null;
                        HideGhostChip();
                    }

                    thisSelectedChip = hitChip;

                    thisSelectedChip.ChipSelected();
                }
                else if (hitChip.idPlayer != idThisPlayer & thisSelectedChip != null)
                {
                    Chip thisDeletedChip = hitChip;
                    if (thisDeletedChip.thisCell == null)
                    {
                        if (thisSelectedChip != null)
                        {
                            thisSelectedChip.ChipUnSelected();
                            thisSelectedChip = null;
                            HideGhostChip();
                        }
                        return;
                    }
                    if (thisDeletedChip.thisCell.GhostChip.gameObject.activeInHierarchy == true)
                    {
                        if (thisDeletedChip.MoveToEnemyBase(thisDeletedChip, thisSelectedChip, thisDeletedChip.thisCell))
                        {
                            if (IsEndRaundOneStep())
                            {
                                if (IsEndRaundTwoStep())
                                {
                                    NextPlayer();
                                }
                                else
                                {
                                    StepOne();
                                }
                            }
                            if (thisSelectedChip != null)
                            {
                                thisSelectedChip.ChipUnSelected();
                                thisSelectedChip = null;
                                HideGhostChip();
                            }
                        }
                    }
                    else
                    {
                        if (thisSelectedChip != null)
                        {
                            thisSelectedChip.ChipUnSelected();
                            thisSelectedChip = null;
                            HideGhostChip();
                        }
                    }
                }
            }
            else if (hit.collider.tag == "Cell")
            {
                Cell hitCell = hit.collider.GetComponent <Cell>();
                if (thisSelectedChip != null & !hitCell.isOccupied)
                {
                    if (hitCell.GhostChip.gameObject.activeInHierarchy == true)
                    {
                        if (thisSelectedChip.MoveToGhostChip(hitCell))
                        {
                            if (IsEndRaundOneStep())
                            {
                                if (IsEndRaundTwoStep())
                                {
                                    NextPlayer();
                                }
                                else
                                {
                                    StepOne();
                                }
                            }
                            thisSelectedChip.ChipUnSelected();
                            thisSelectedChip = null;
                        }
                        else
                        {
                            Debug.Log("CheckChipsOnField() = " + CheckChipsOnField());
                            if (CheckChipsOnField() == false & CheckPlayersScoreIsSixScore() == false)
                            {
                                NextPlayer();
                            }
                            HideGhostChip();
                            thisSelectedChip.ChipUnSelected();
                            thisSelectedChip = null;
                        }
                    }
                    else
                    {
                        Debug.Log("CheckChipsOnField() = " + CheckChipsOnField());
                        if (CheckChipsOnField() == false & CheckPlayersScoreIsSixScore() == false)
                        {
                            NextPlayer();
                        }
                        HideGhostChip();
                        thisSelectedChip.ChipUnSelected();
                        thisSelectedChip = null;
                    }
                }
                else
                {
                    if (thisSelectedChip != null)
                    {
                        Debug.Log("CheckChipsOnField() = " + CheckChipsOnField());
                        if (CheckChipsOnField() == false & CheckPlayersScoreIsSixScore() == false)
                        {
                            NextPlayer();
                        }
                        HideGhostChip();
                        thisSelectedChip.ChipUnSelected();
                        thisSelectedChip = null;
                    }
                }
            }
            Debug.Log(hit.collider.name);
        }
        else if (Input.GetMouseButtonDown(0))
        {
            if (thisSelectedChip != null)
            {
                thisSelectedChip.ChipUnSelected();
                thisSelectedChip = null;
                HideGhostChip();
            }
        }
    }