Exemple #1
0
    public void OnReceiveUnitAttackPacket(PacketId id, byte[] data)
    {
        UnitAttackPacket packet = new UnitAttackPacket(data);
        UnitAttackData   attack = packet.GetPacket();
        int attack_id           = attack.unitId;
        int defener_id          = attack.targetUnidId;

        unitAttack.InitiateUnitAttack(attack_id);
        unitAttack.DoAttack(defener_id);
    }
Exemple #2
0
    IEnumerator CheckTiled()
    {
        while (check)
        {
            if (!movecheck)
            {
                firstClick = true;
                if (Input.GetMouseButtonDown(0))
                {
                    Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Ray2D   ray = new Ray2D(pos, Vector2.zero);
                    rayhit = Physics2D.Raycast(ray.origin, ray.direction);

                    if (rayhit.collider != null)
                    {
                        if (attackCheck == false)
                        {
                            if (rayhit.collider.gameObject.tag == "Tiled")
                            {
                                if (rayhit.collider.GetComponent <Tiledcontrol1>().tiledUnitCheck == false) //자신의 유닛 위치로 이동못하게 막아주는 변수
                                {
                                    if (rayhit.collider.GetComponent <SpriteRenderer>().color == Color.blue)
                                    {
                                        if (rayhit.collider.transform.position.x < transform.position.x)
                                        {
                                            filpCheck = true;
                                        }
                                        else
                                        {
                                            filpCheck = false;
                                        }
                                        tempPos         = transform.position;
                                        movecheck       = true;
                                        bMovefirstCheck = true;
                                        //setPos(rayhit.collider.transform.position.x, y);
                                        //네트워크 지정필요
                                    }
                                }
                            }
                            else if (rayhit.collider.gameObject.layer == 0) //임시작업중 다른곳 클릭스 선택해제
                            {
                                Debug.Log("다른곳 클릭1");
                                GameUIManager.Instance.SelectUnit(this);
                                clickCheck       = false;
                                attackCheck      = false;
                                check            = false;
                                gameObject.layer = 0;
                                GameManager.GetInstance.currentUnit = false;
                                rightEnemy       = null;
                                leftEnemy        = null;
                                enemyattackCheck = false;
                            }
                        }
                        else if (attackCheck)
                        {
                            Vector2 aPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                            Ray2D   aRay = new Ray2D(aPos, Vector2.zero);
                            rayhit = Physics2D.Raycast(aRay.origin, aRay.direction);

                            if (rayhit.collider.transform.tag == "unit")
                            {
                                if (transform.GetComponent <Unit>().control_player == PLAYER.PLAYER1 && rayhit.collider.GetComponent <Unit>().control_player == PLAYER.PLAYER2 ||
                                    transform.GetComponent <Unit>().control_player == PLAYER.PLAYER2 && rayhit.collider.GetComponent <Unit>().control_player == PLAYER.PLAYER1)
                                {
                                    if (rayhit.collider.GetComponent <Unit>().enemyattackCheck)
                                    {
                                        Debug.Log(rayhit.collider.GetComponent <Unit>().unitID);
                                        m_unitAttack.DoAttack(rayhit.collider.GetComponent <Unit>().unitID);
                                    }
                                }
                                else
                                {
                                    attackCheck = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (firstClick)  //임시작업중 다른곳 클릭스 선택해제
                        {
                            Debug.Log("다른곳 클릭");
                            GameUIManager.Instance.SelectUnit(this);
                            GameManager.GetInstance.currentUnit = false;
                            clickCheck       = false;
                            attackCheck      = false;
                            check            = false;
                            rightEnemy       = null;
                            leftEnemy        = null;
                            gameObject.layer = 0;
                            enemyattackCheck = false;
                        }
                    }
                }
                else if (Input.GetKeyDown(KeyCode.A))
                {
                    attackCheck = !attackCheck;
                }
            }

            if (movecheck)
            {
                clickCheck = false;
                ClientUnitMove(rayhit.collider.transform.position.x, y);
                if (movecheck == false)
                {
                    clickCheck = true;
                }
            }


            yield return(null);
        }
    }