Пример #1
0
    IEnumerator LockCheck()
    {
        gateLocks = Physics.OverlapSphere(myTr.position, 5f, lockLayer);

        if (gateLocks.Length >= 1)
        {
            float     closestSqr    = Mathf.Infinity;                  //가장 가까운 거리
            Transform closestTarget = null;                            //가장 가까운 타겟
            float     targetDist;                                      //자신과 타겟과의 거리
            for (int i = 0; i < gateLocks.Length; i++)                 //검색
            {
                Vector3 objectPos = gateLocks[i].transform.position;   //찾은 타겟의 포지션
                targetDist = (objectPos - myTr.position).sqrMagnitude; //자신과 새 타겟과의 현재 거리

                if (targetDist < closestSqr)                           //새 타겟과의 현재 거리가 기존 타겟보다 가까우면
                {
                    closestSqr    = targetDist;                        //현재 거리가 가장 가까운 거리가 됨
                    closestTarget = gateLocks[i].transform;            //가장 가까운 타겟은 지금 거리계산한 타겟
                }
            }
            targetTr = closestTarget.transform; //타겟은 가장 가까운 타겟
            if (targetTr.CompareTag("PC"))
            {
                hackingPC = targetTr.GetComponent <HackingPC>();
            }
            else
            {
                gateAccess = targetTr.GetComponent <GateAccess>();
            }

            yield return(StartCoroutine(HackingStart()));
        }
        else
        {
            print("해킹대상 없음");
            currentState           = CurrentState.hackingOff;
            isHacking              = false;
            droneManager.currState = DroneManager.CurrentState.idle;
            StartCoroutine(droneManager.SwitchUtile());
            yield return(null);
        }
    }
Пример #2
0
    IEnumerator HackingStart()
    {
        while (targetTr != null)
        {
            myTr.LookAt(targetTr);
            heading = targetTr.position - myTr.position;
            if (heading.sqrMagnitude > minDistance) //해킹장소가 멀면 이동
            {
                myTr.position = Vector3.Lerp(myTr.position
                                             , targetTr.position
                                             , Time.deltaTime * dampSpeed);
            }
            else //해킹장소가 가까우면
            {
                if (gateAccess != null)
                {
                    gateAccess.enabled   = true;
                    gateAccess.isHacking = true;
                }
                if (hackingPC != null)
                {
                    hackingPC.enabled   = true;
                    hackingPC.isHacking = true;
                }


                //빔 쏘기

                /*if(!scanBeam.gameObject.activeSelf)
                 *  scanBeam.gameObject.SetActive(true);
                 *
                 * scanBeamRotX = scanBeam.eulerAngles.x;
                 * if(scanBeamRotX <= -150f)
                 * {
                 *  Vector3.Lerp(myTr.eulerAngles
                 *             , new Vector3(-30f, 0f, 0f)
                 *             , Time.deltaTime * dampSpeed);
                 * }
                 * if(scanBeamRotX >= -30f)
                 * {
                 *  Vector3.Lerp(myTr.eulerAngles
                 *             , new Vector3(-150f, 0f, 0f)
                 *             , Time.deltaTime * dampSpeed);
                 * }*/

                currTime += 1f * Time.deltaTime;
                if (currTime >= maxTime) //일정 시간이 되면
                {
                    targetTr.gameObject.layer = 0;
                    targetTr               = null;
                    hackingPC              = null;
                    gateAccess             = null;
                    isHacking              = false;
                    currTime               = 0f;
                    currentState           = CurrentState.hackingOff;
                    droneManager.currState = DroneManager.CurrentState.idle;
                    StartCoroutine(droneManager.SwitchUtile());
                }
            }
            yield return(null);
        }
    }
Пример #3
0
 private void OnEnable()
 {
     audioSource  = this.GetComponent <AudioSource>();
     meshRenderer = this.GetComponent <MeshRenderer>();
     gateAccess   = this.GetComponent <GateAccess>();
 }