Exemple #1
0
 private void Update()
 {
     if (SceneManager.GetActiveScene().name.Equals("InGame") && EventSystem.current.IsPointerOverGameObject() == false) // 인게임에서 A키를 사용한 강제어택
     {
         if (chatfunction.chatInput.IsActive())
         {
             return;
         }
         //마우스 커서-------------------------------------------------------------------------------
         if (Input.GetKeyDown(KeyCode.A))
         {
             if (!forceAtk)
             {
                 forceAtk = true;
                 SetCursor(3, Vector2.zero);
             }
             else
             {
                 forceAtk = false;
                 SetCursor(PreCursor, Vector2.zero);
             }
         }
         else if (Input.GetMouseButtonDown(0) && forceAtk)
         {
             SetCursor(0, Vector2.zero);
             forceAtk = false;
             fxPool.GetPool("Force", Target.position);
         }
     }
 }
    private void Update()
    {
        //딜레이 타임 확인
        CheckAtkDelayTime();

        //와드 설치 명령이 있다면 와드를 설치한다
        if (isWarding)
        {
            InstallWard();
        }

        //논 타겟팅 어택 명령이 있다면 적 리스트에 있는 이 중 가장 가까운 이를 찾는다.
        if (isWillAtkAround)
        {
            float      dist = 1000000, nowDist;
            GameObject tempObj = null;

            for (int i = 0; i < enemiesList.Count; ++i)
            {
                if (enemiesList[i].tag.Equals("Tower"))
                {
                    TowerBehaviour towerBehav = enemiesList[i].GetComponent <TowerBehaviour>();

                    if (!towerBehav.isCanAtkMe)
                    {
                        continue;
                    }

                    if (towerBehav.team == myChampBehav.team)
                    {
                        continue;
                    }
                }
                else if (enemiesList[i].tag.Equals("Suppressor") || enemiesList[i].tag.Equals("Nexus"))
                {
                    SuppressorBehaviour supBehav = enemiesList[i].GetComponent <SuppressorBehaviour>();

                    if (!supBehav.isCanAtkMe)
                    {
                        continue;
                    }

                    if (supBehav.team == myChampBehav.team)
                    {
                        continue;
                    }
                }
                else if (enemiesList[i].layer.Equals(LayerMask.NameToLayer("Monster")))
                {
                    MonsterBehaviour monBehav = enemiesList[i].GetComponent <MonsterBehaviour>();

                    if (!monBehav.TheFogEntity.isCanTargeting)
                    {
                        continue;
                    }

                    if (!monBehav.monAtk.isAtking)
                    {
                        continue;
                    }
                }
                else if (enemiesList[i].layer.Equals(LayerMask.NameToLayer("Champion")))
                {
                    ChampionBehavior champBehav = enemiesList[i].GetComponent <ChampionBehavior>();

                    if (champBehav.team == myChampBehav.team)
                    {
                        continue;
                    }
                }

                nowDist = (enemiesList[i].transform.position - myChamp.transform.position).sqrMagnitude;

                if (dist > nowDist)
                {
                    dist    = nowDist;
                    tempObj = enemiesList[i];
                }

                // 만약 타겟팅할 적을 찾았다면 타겟팅한다
                if (tempObj != null)
                {
                    atkTargetObj    = tempObj;
                    isTargetting    = true;
                    isWillAtkAround = false;
                    fxpool.GetPool("Force", tempObj.transform.position, tempObj.transform.gameObject);
                }
            }
        }

        // 공격할 적이 있는 경우
        if (atkTargetObj != null)
        {
            if (isTargetting && atkTargetObj.activeInHierarchy)
            {
                if (TheAIDest.target != atkTargetObj.transform)
                {
                    TheAIDest.target = atkTargetObj.transform;
                }

                atkTargetPos   = atkTargetObj.transform.position;
                myChampPos     = myChamp.transform.position;
                atkTargetPos.y = 0;
                myChampPos.y   = 0;
                float atkRevision = 0;

                // 건물의 반지름에 따라 거리 보정을 넣어준다
                if (atkTargetObj.tag.Equals("Tower") && atkRange < 5)
                {
                    atkRevision = 1f;
                }
                else if (atkTargetObj.tag.Equals("Suppressor") && atkRange < 5)
                {
                    atkRevision = 2.5f;
                }
                else if (atkTargetObj.tag.Equals("Nexus") && atkRange < 5)
                {
                    atkRevision = 7f;
                }

                // 공격 반경 밖에 타겟이 있다면 다가간다
                if (Vector3.Distance(atkTargetPos, myChampPos) > atkRange + atkRevision)
                {
                    if (!TheAIPath.canMove)
                    {
                        ToggleMove(true);
                        myChampionAnimation.AttackAnimation(false);
                    }

                    if (atkCoroutine != null)
                    {
                        myChampionAnimation.AttackAnimation(false);
                        StopCoroutine(atkCoroutine);
                        atkCoroutine = null;
                    }
                }
                else
                {// 공격 반경 안에 타겟이 있다면 공격한다
                    if (!isAtkDelayTime)
                    {
                        if (TheAIPath.canMove)
                        {
                            ToggleMove(false);
                            myChampionAnimation.AttackAnimation(true);
                        }

                        if (atkCoroutine == null)
                        {
                            atkCoroutine = StartCoroutine(Attack());
                        }
                    }
                }
            }
            else
            {
                ResetTarget();
            }
        }
        else
        {
            ResetTarget();
        }

        // 시간이 지난 만큼 와드의 쿨타임을 감소시킨다
        CheckMadeWardCooldown();
    }
    /// <summary>
    /// 어택 단축키를 누른 후 마우스 왼쪽을 클릭했을 때 작동하는 함수
    /// </summary>
    private void AtkKeyAndLeftClick()
    {
        isAtkCommand = false;
        Vector3    h             = Vector3.zero;
        GameObject target        = null;
        bool       isTouchGround = false;
        bool       isTouchEnemy  = false;

        v    = Input.mousePosition;
        r    = Camera.main.ScreenPointToRay(v);
        hits = Physics.RaycastAll(r);

        //레이를 쏴 충돌한게 있다면, 충돌한 개체마다 확인
        foreach (RaycastHit hit in hits)
        {
            //땅과 충돌했을 때
            if (hit.collider.tag.Equals("Terrain"))
            {
                h   = hit.point;
                h.y = 1;
                //땅과 충돌했음을 체크한다.
                isTouchGround = true;
            }
            else //적과 충돌했는지 확인한다.
            {
                isTouchEnemy = CheckTouchEnemy(hit);
            }

            //적과 레이가 충돌했다면 타겟을 충돌한 오브젝트로 설정한다.
            if (isTouchEnemy)
            {
                target = hit.collider.gameObject;
                break;
            }
        }

        //레이를 쏴 검사한 결과 적을 클릭한 경우 적을 타겟팅
        if (isTouchEnemy)
        {
            myChampAtk.isWillAtkAround = false;

            if (!myChampAtk.isTargetting)
            {
                myChampAtk.isTargetting = true;
                myChampAtk.isWarding    = false;
            }

            myChampAtk.atkTargetObj = target;
            fxPool.GetPool("Force", myChampAtk.atkTargetObj.transform.position, myChampAtk.atkTargetObj);
        }
        else if (isTouchGround)
        {//땅을 클릭한 경우
            fxPool.GetPool("Force", h);
            myTarget.transform.position = h;
            myChampAtk.isWillAtkAround  = true;

            //개체가 타겟팅된 경우는 아니므로 타겟팅 false 처리해줌.
            if (myChampAtk.isTargetting)
            {
                myChampAtk.isTargetting = false;
                myChampAtk.isWarding    = false;
                myChampAtk.atkTargetObj = null;
            }
        }

        //귀환중에 클릭을 했다면 귀환캔슬
        myChampData.RecallCancel();
    }
Exemple #4
0
    private void Update()
    {
        if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Equals("InGame"))
        {
            if (PlayerData.Instance.isDead)
            {
                return;
            }
            if (Input.GetKeyDown(KeyCode.A))
            {
                atkCommand  = !atkCommand;
                wardCommand = false;
            }
            else if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                if (PlayerData.Instance.accessoryItem.Equals(1))
                {
                    wardCommand = !wardCommand;
                    if (wardCommand)
                    {
                        if (myChampAtk.wardAmount < 1)
                        {
                            wardCommand = false;
                            atkCommand  = false;
                        }
                    }
                }
            }
            else if (Input.GetKeyDown(KeyCode.S))
            {
                myChampAtk.Stop();
            }
            if (Input.GetMouseButtonDown(1))
            {
                soundtimer -= Time.deltaTime;
                if (soundtimer <= 0)
                {
                    ChampionSound.instance.WalkSound(myChampName);
                    soundtimer = 5.0f;
                }
                //우선 이동만. 나중엔 공격인지 뭔지 그런 것 판단도 해야 할 것.
                if (atkCommand)
                {
                    atkCommand = false;
                }
                if (wardCommand)
                {
                    if (myChampAtk.wardAmount > 0)
                    {
                        wardCommand = false;
                    }
                }

                Vector3    h           = Vector3.zero;
                GameObject target      = null;
                bool       touchGround = false;
                bool       touchEnemy  = false;

                v    = Input.mousePosition;
                r    = Camera.main.ScreenPointToRay(v);
                hits = Physics.RaycastAll(r);
                foreach (RaycastHit hit in hits)
                {
                    if (hit.collider.tag.Equals("Terrain"))
                    {
                        h           = hit.point;
                        h.y         = 1;
                        touchGround = true;
                        if (!fxpool && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "InGame")
                        {
                            fxpool = GameObject.FindGameObjectWithTag("MouseFxPool").GetComponent <MouseFxPooling>();
                        }
                        fxpool.GetPool("Default", h);
                    }
                    else if (hit.collider.tag.Equals("Minion"))
                    {
                        if (!hit.collider.name.Contains(playerTeam))
                        {
                            if (hit.collider.GetComponent <FogOfWarEntity>().isCanTargeting)
                            {
                                touchEnemy = true;
                            }
                        }
                    }
                    else if (hit.collider.gameObject.layer.Equals(LayerMask.NameToLayer("Champion")))
                    {
                        if (!hit.collider.gameObject.GetComponent <ChampionBehavior>().Team.Equals(playerTeam))
                        {
                            if (hit.collider.GetComponent <FogOfWarEntity>().isCanTargeting)
                            {
                                touchEnemy = true;
                            }
                        }
                    }
                    else if (hit.collider.tag.Equals("Tower"))
                    {
                        TowerBehaviour t = hit.collider.gameObject.GetComponent <TowerBehaviour>();
                        if (t.isCanAtkMe)
                        {
                            if (!t.Team.Equals(playerTeam))
                            {
                                //if (hit.collider.GetComponent<FogOfWarEntity>().isCanTargeting)
                                touchEnemy = true;
                            }
                        }
                    }
                    else if (hit.collider.tag.Equals("Suppressor") || hit.collider.tag.Equals("Nexus"))
                    {
                        SuppressorBehaviour s = hit.collider.gameObject.GetComponent <SuppressorBehaviour>();
                        if (s.isCanAtkMe)
                        {
                            if (!s.Team.Equals(playerTeam))
                            {
                                //if (hit.collider.GetComponent<FogOfWarEntity>().isCanTargeting)
                                touchEnemy = true;
                            }
                        }
                    }
                    else if (hit.collider.gameObject.layer.Equals(LayerMask.NameToLayer("Monster")))
                    {
                        if (hit.collider.GetComponent <FogOfWarEntity>().isCanTargeting)
                        {
                            touchEnemy = true;
                        }
                    }
                    if (touchEnemy)
                    {
                        target = hit.collider.gameObject;
                        break;
                    }
                }

                // 상점 켜져있으면 뒤로 움직이지않게
                var shop = GameObject.FindGameObjectWithTag("ShopCanvas");
                if (shop != null)
                {
                    GraphicRaycaster ShopGR = shop.GetComponent <GraphicRaycaster>();
                    PointerEventData ped    = new PointerEventData(null);
                    ped.position = Input.mousePosition;
                    List <RaycastResult> results = new List <RaycastResult>();
                    ShopGR.Raycast(ped, results);
                    foreach (RaycastResult result in results)
                    {
                        if (result.gameObject.transform.GetComponentInParent <GraphicRaycaster>().Equals(ShopGR))
                        {
                            touchEnemy  = false;
                            touchGround = false;
                            break;
                        }
                    }
                }

                // 옵션 켜져있으면 움직이지않게
                var optionCanvas = GameObject.FindGameObjectWithTag("OptionCanvas");
                if (optionCanvas != null)
                {
                    GraphicRaycaster OptionGR = optionCanvas.GetComponent <GraphicRaycaster>();
                    PointerEventData ped      = new PointerEventData(null);
                    ped.position = Input.mousePosition;
                    List <RaycastResult> results = new List <RaycastResult>();
                    OptionGR.Raycast(ped, results);
                    foreach (RaycastResult result in results)
                    {
                        if (result.gameObject.transform.GetComponentInParent <GraphicRaycaster>().Equals(OptionGR))
                        {
                            touchEnemy  = false;
                            touchGround = false;
                            break;
                        }
                    }
                }

                if (touchEnemy)
                {
                    myTarget.transform.position = transform.position;
                    myChampAtk.willAtkAround    = false;
                    if (!myChampAtk.isTargetting)
                    {
                        myChampAtk.isTargetting = true;
                        myChampAtk.AtkTargetObj = target;
                    }
                }
                else if (touchGround)
                {
                    //if (MinimapClick.IsPointerOver)
                    //    return;
                    myTarget.transform.position = h;
                    myChampAtk.willAtkAround    = false;
                    if (myChampAtk.isTargetting)
                    {
                        myChampAtk.isTargetting        = false;
                        myChampAtk.AtkTargetObj        = null;
                        myChampAtk.TheAIPath.canMove   = true;
                        myChampAtk.TheAIPath.canSearch = true;
                    }
                }
            }
            else if (Input.GetMouseButtonDown(0))
            {
                if (atkCommand)
                {
                    atkCommand = false;
                    Vector3    h           = Vector3.zero;
                    GameObject target      = null;
                    bool       touchGround = false;
                    bool       touchEnemy  = false;
                    v    = Input.mousePosition;
                    r    = Camera.main.ScreenPointToRay(v);
                    hits = Physics.RaycastAll(r);
                    foreach (RaycastHit hit in hits)
                    {
                        if (hit.collider.tag.Equals("Terrain"))
                        {
                            h           = hit.point;
                            h.y         = 1;
                            touchGround = true;
                            fxpool.GetPool("Force", h);
                        }
                        else if (hit.collider.tag.Equals("Minion"))
                        {
                            if (!hit.collider.name.Contains(playerTeam))
                            {
                                if (hit.collider.GetComponent <FogOfWarEntity>().isCanTargeting)
                                {
                                    touchEnemy = true;
                                }
                            }
                            fxpool.GetPool("Force", h, hit.transform.gameObject);
                        }
                        else if (hit.collider.gameObject.layer.Equals(LayerMask.NameToLayer("Champion")))
                        {
                            if (!hit.collider.gameObject.GetComponent <ChampionBehavior>().Team.Equals(playerTeam))
                            {
                                if (hit.collider.GetComponent <FogOfWarEntity>().isCanTargeting)
                                {
                                    touchEnemy = true;
                                }
                            }
                            fxpool.GetPool("Force", h, hit.transform.gameObject);
                        }
                        else if (hit.collider.tag.Equals("Tower"))
                        {
                            TowerBehaviour t = hit.collider.gameObject.GetComponent <TowerBehaviour>();
                            if (t.isCanAtkMe)
                            {
                                if (!t.Team.Equals(playerTeam))
                                {
                                    //if (hit.collider.GetComponent<FogOfWarEntity>().isCanTargeting)
                                    touchEnemy = true;
                                }
                            }
                        }
                        else if (hit.collider.tag.Equals("Suppressor") || hit.collider.tag.Equals("Nexus"))
                        {
                            SuppressorBehaviour s = hit.collider.gameObject.GetComponent <SuppressorBehaviour>();
                            if (s.isCanAtkMe)
                            {
                                if (!s.Team.Equals(playerTeam))
                                {
                                    //if (hit.collider.GetComponent<FogOfWarEntity>().isCanTargeting)
                                    touchEnemy = true;
                                }
                            }
                        }
                        else if (hit.collider.gameObject.layer.Equals(LayerMask.NameToLayer("Monster")))
                        {
                            //if (hit.collider.GetComponentInChildren<MonsterBehaviour>().monAtk.isAtking)//정글이 누굴 공격중이다
                            if (hit.collider.GetComponent <FogOfWarEntity>().isCanTargeting)
                            {
                                touchEnemy = true;
                            }
                            fxpool.GetPool("Force", h, hit.transform.gameObject);
                        }
                        if (touchEnemy)
                        {
                            target = hit.collider.gameObject;
                            break;
                        }
                    }

                    if (touchEnemy)
                    {
                        //myTarget.transform.position = transform.position;
                        myChampAtk.willAtkAround = false;
                        if (!myChampAtk.isTargetting)
                        {
                            myChampAtk.isTargetting = true;
                            myChampAtk.isWarding    = false;
                            myChampAtk.AtkTargetObj = target;
                        }
                    }
                    else if (touchGround)
                    {//여기 고치기
                        myTarget.transform.position = h;
                        myChampAtk.willAtkAround    = true;
                        if (myChampAtk.isTargetting)
                        {
                            myChampAtk.isTargetting = false;
                            myChampAtk.isWarding    = false;
                            myChampAtk.AtkTargetObj = null;
                        }
                    }
                }
                else if (wardCommand)
                {
                    Vector3 h = Vector3.zero;
                    v    = Input.mousePosition;
                    r    = Camera.main.ScreenPointToRay(v);
                    hits = Physics.RaycastAll(r);
                    foreach (RaycastHit hit in hits)
                    {
                        if (hit.collider.tag.Equals("Terrain"))
                        {
                            h   = hit.point;
                            h.y = 1;
                            bool       isNotCollision = true;
                            Collider[] Cols           = Physics.OverlapSphere(h, 1f);
                            foreach (Collider a in Cols)
                            {
                                if (a.tag.Equals("WarCollider"))
                                {
                                    isNotCollision = false;
                                    break;
                                }
                            }
                            if (isNotCollision)
                            {
                                wardCommand = false;
                                myChampAtk.WantBuildWard(h);
                            }
                        }
                    }
                }
            }
        }
    }