コード例 #1
0
    void Update()
    {
        // 사용자의 입력에 따라 앞뒤좌우로 이동하고 싶다.
        // 1. 사용자의 입력을 받는다.
        float h = ARAVRInput.GetAxis("Horizontal");
        float v = ARAVRInput.GetAxis("Vertical");
        // 2. 방향을 만든다.
        Vector3 dir = new Vector3(h, 0, v);

        // 2.0 사용자가 바라보는 방향으로 입력 값을 변화 시키기
        dir = Camera.main.transform.TransformDirection(dir);

        // 2.1 중력 적용한 수직 방향 추가 v=v0+at
        yVelocity += gravity * Time.deltaTime;

        // 2.2 바닥에 있을 경우 수직항력처리를 위해 속도를 0으로 한다.
        if (cc.isGrounded)
        {
            yVelocity = 0;
        }

        // 2.3 사용자가 점프버튼을 누르면 속도에 점프크기를 할당한다.
        if (ARAVRInput.GetDown(ARAVRInput.Button.Two, ARAVRInput.Controller.RTouch))
        {
            yVelocity = jumpPower;
        }

        dir.y = yVelocity;

        // 3. 이동한다.
        cc.Move(dir * speed * Time.deltaTime);

        // 오른쪽 터치패드 혹은 썸스틱을 아래로 내리면 Recenter 한다.
        float recenter = ARAVRInput.GetAxis("Vertical", ARAVRInput.Controller.RTouch);

        if (recenter < 0)
        {
            if (!bRecentering)
            {
                ARAVRInput.Recenter(transform, Vector3.back);
                //ARAVRInput.Recenter();
            }
            bRecentering = true;
        }
        else
        {
            bRecentering = false;
        }
    }
コード例 #2
0
    void Update()
    {
        // 크로스헤어 표시
        ARAVRInput.DrawCrosshair(crosshair);

        // 사용자가 IndexTrigger 버튼을 누르면
        if (ARAVRInput.GetDown(ARAVRInput.Button.One))
        {
            // 컨트롤러의 진동 재생
            ARAVRInput.PlayVibration(ARAVRInput.Controller.RTouch);

            // 총알 오디오 재생
            bulletAudio.Stop();
            bulletAudio.Play();

            // Ray 를 카메라의 위치로 부터 나가도록 만든다.
            Ray ray = new Ray(ARAVRInput.RHandPosition, ARAVRInput.RHandDirection);
            // Ray 의 충돌정보를 저장하기 위한 변수 지정
            RaycastHit hitInfo;
            // 플레이어 레이어 얻어오기
            int playerLayer = 1 << LayerMask.NameToLayer("Player");
            // 타워 레이어 얻어오기
            int towerLayer = 1 << LayerMask.NameToLayer("Tower");
            int layerMask  = playerLayer | towerLayer;
            // Ray 를 쏜다. ray 가 부딪힌 정보는 hitInfo 에 담긴다.
            if (Physics.Raycast(ray, out hitInfo, 200, ~layerMask))
            {
                // 총알파편효과 처리
                // 총알 이펙트 진행되고 있으면 멈추고 재생
                bulletEffect.Stop();
                bulletEffect.Play();
                // 부딪힌 지점의 방향으로 총알 이펙트 방향을 설정
                bulletImpact.up = hitInfo.normal;
                // 부딪힌 지점 바로 위에서 이펙트가 보여지도록 설정
                bulletImpact.position = hitInfo.point;

                // ray 와 부딪힌 객체가 drone 이라면 폭발효과 처리
                if (hitInfo.transform.name.Contains("Drone"))
                {
                    DroneAI drone = hitInfo.transform.GetComponent <DroneAI>();
                    if (drone)
                    {
                        drone.OnDamageProcess();
                    }
                }
            }
        }
    }
コード例 #3
0
    private void TryGrab()
    {
        // Grab 버튼을 누르면 일정영역안에 있는 폭탄을 잡는다.
        // 1. grab 버튼을 눌렀다면
        if (ARAVRInput.GetDown(ARAVRInput.Button.HandTrigger, ARAVRInput.Controller.RTouch))
        {
            int closest = 0;

            // 2. 일정영역 안에 폭탄이 있으니까
            // - 영역안에 있는 모든 폭탄 검출
            Collider[] hitObjects = Physics.OverlapSphere(ARAVRInput.RHandPosition, grabRange, grabbedLayer);
            // - 손과 가장 가까운 물체 선택
            for (int i = 1; i < hitObjects.Length; i++)
            {
                // 손과 가장 가까운 물체와의 거리
                Vector3 closestPos      = hitObjects[closest].transform.position;
                float   closestDistance = Vector3.Distance(closestPos, ARAVRInput.RHandPosition);
                // 다음 물체와 손과의 거리
                Vector3 nextPos      = hitObjects[i].transform.position;
                float   nextDistance = Vector3.Distance(nextPos, ARAVRInput.RHandPosition);
                // 다음 물체와의 거리가 더 가깝다면
                if (nextDistance < closestDistance)
                {
                    // 가장가까운 물체 인덱스 교체
                    closest = i;
                }
            }
            // 3. 폭탄을 잡는다.
            // - 검출된 물체가 있을 경우
            if (hitObjects.Length > 0)
            {
                // 잡은 상태로 전환
                isGrabbing = true;
                // 잡은 물체기억
                grabbedObject = hitObjects[closest].gameObject;
                // 잡은 물체를 손의 자식으로 등록
                grabbedObject.transform.parent = ARAVRInput.RHand;

                // 물리기능 정지
                grabbedObject.GetComponent <Rigidbody>().isKinematic = true;
                // 초기 위치값 지정
                prevPos = ARAVRInput.RHand.position;
                // 초기 회전 값 지정
                prevRot = ARAVRInput.RHand.rotation;
            }
        }
    }
コード例 #4
0
    void Update()
    {
        // 왼쪽 컨트롤러의 One 버튼을 누르면
        if (ARAVRInput.GetDown(ARAVRInput.Button.One, ARAVRInput.Controller.LTouch))
        {
            // 라인랜더러 컴포넌트 활성화
            lr.enabled = true;
        }
        // 왼쪽 컨트롤러의 One 버튼을 떼면
        else if (ARAVRInput.GetUp(ARAVRInput.Button.One, ARAVRInput.Controller.LTouch))
        {
            // 라인랜더러 비활성화
            lr.enabled = false;
            if (teleportCircleUI.gameObject.activeSelf)
            {
                // 워프 기능 사용이 아닐때 순간이동 처리
                if (isWarp == false)
                {
                    GetComponent <CharacterController>().enabled = false;
                    // 텔레포트 UI 위치로 순간이동
                    transform.position = teleportCircleUI.position + Vector3.up;
                    GetComponent <CharacterController>().enabled = true;
                }
                else
                {
                    // 워프 기능 사용할때는 Warp() 코루틴 호출
                    StartCoroutine(Warp());
                }
            }
            // 텔레포트 UI 비활성화
            teleportCircleUI.gameObject.SetActive(false);
        }
        // 왼쪽 컨트롤러의 One 버튼을 누르고 있을때
        else if (ARAVRInput.Get(ARAVRInput.Button.One, ARAVRInput.Controller.LTouch))
        {
            // 1. 왼쪽 컨트롤러를 기준으로 Ray 를 만든다.
            Ray        ray = new Ray(ARAVRInput.LHandPosition, ARAVRInput.LHandDirection);
            RaycastHit hitInfo;
            int        layer = 1 << LayerMask.NameToLayer("Terrain");
            // 2. Terrain 만 Ray 충돌 검출
            if (Physics.Raycast(ray, out hitInfo, 200, layer))
            {
                // 3. Ray 가 부딪힌 지점에 라인그리기
                lr.SetPosition(0, ray.origin);
                lr.SetPosition(1, hitInfo.point);

                // 4. Ray 가 부딪힌 지점에 텔레포트 UI 표시
                teleportCircleUI.gameObject.SetActive(true);
                teleportCircleUI.position = hitInfo.point;
                // 텔레포트 UI 가 위로 누워 있도록 방향 설정
                teleportCircleUI.forward = hitInfo.normal;
                // 텔레포트 UI 의 크기가 거리에 따라 보정 되도록 설정
                teleportCircleUI.localScale = originScale * Mathf.Max(1, hitInfo.distance);
            }
            else
            {
                // Ray 충돌이 발생하지 않으면 선이 Ray 방향으로 그려지도록 처리
                lr.SetPosition(0, ray.origin);
                lr.SetPosition(1, ray.origin + ARAVRInput.LHandDirection * 200);
                // 텔레포트 UI 는 화면에서 비활성화
                teleportCircleUI.gameObject.SetActive(false);
            }
        }
    }
コード例 #5
0
    private void TryGrab()
    {
        // Grab 버튼을 누르면 일정영역안에 있는 폭탄을 잡는다.
        // 1. grab 버튼을 눌렀다면
        if (ARAVRInput.GetDown(ARAVRInput.Button.HandTrigger, ARAVRInput.Controller.RTouch))
        {
            // 원거리 물체 잡기 사용한다면
            if (isRemoteGrab)
            {
                // 손방향으로 레이 제작
                Ray        ray = new Ray(ARAVRInput.RHandPosition, ARAVRInput.RHandDirection);
                RaycastHit hitInfo;
                // SphereCast 를 이용하여 물체 충돌 체크
                if (Physics.SphereCast(ray, 0.5f, out hitInfo, remoteGrabDistance, grabbedLayer))
                {
                    // 잡은 상태로 전환
                    isGrabbing = true;
                    // 잡은 물체기억
                    grabbedObject = hitInfo.transform.gameObject;
                    // 물체가 끌려오는 기능 실행
                    StartCoroutine(GrabbingAnimation());
                }
                return;
            }

            int closest = 0;

            // 2. 일정영역 안에 폭탄이 있으니까
            // - 영역안에 있는 모든 폭탄 검출
            Collider[] hitObjects = Physics.OverlapSphere(ARAVRInput.RHandPosition, grabRange, grabbedLayer);

            // - 손과 가장 가까운 물체 선택
            for (int i = 1; i < hitObjects.Length; i++)
            {
                // 손과 가장 가까운 물체와의 거리
                Vector3 closestPos      = hitObjects[closest].transform.position;
                float   closestDistance = Vector3.Distance(closestPos, ARAVRInput.RHandPosition);
                // 다음 물체와 손과의 거리
                Vector3 nextPos      = hitObjects[i].transform.position;
                float   nextDistance = Vector3.Distance(nextPos, ARAVRInput.RHandPosition);
                // 다음 물체와의 거리가 더 가깝다면
                if (nextDistance < closestDistance)
                {
                    // 가장가까운 물체 인덱스 교체
                    closest = i;
                }
            }
            // 3. 폭탄을 잡는다.
            // - 검출된 물체가 있을 경우
            if (hitObjects.Length > 0)
            {
                // 잡은 상태로 전환
                isGrabbing = true;
                // 잡은 물체기억
                grabbedObject = hitObjects[closest].gameObject;
                // 잡은 물체를 손의 자식으로 등록
                grabbedObject.transform.parent = ARAVRInput.RHand;

                // 물리기능 정지
                grabbedObject.GetComponent <Rigidbody>().isKinematic = true;
                // 초기 위치값 지정
                prevPos = ARAVRInput.RHandPosition;
                // 초기 회전 값 지정
                prevRot = ARAVRInput.RHand.rotation;
            }
        }
    }