using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.XR; using UnityEngine.XR; public class AvatarMove : MonoBehaviour { private float moveSpeed = 9f; private float rotaveSpeed = 8f; private Vector3 moveDirection; private Vector3 angleDirection; public Camera cam; public GameObject ray, leftHand, rightHand; Player player; bool isClick; private void Awake() { //track = cam.GetComponent(); player = GetComponent(); //ray = transform.GetChild(0).GetChild(0).gameObject; //leftHand = transform.GetChild(0).GetChild(1).gameObject; //rightHand = transform.GetChild(0).GetChild(2).gameObject; } private void Start() { cam.gameObject.transform.position = Vector3.zero; cam.gameObject.transform.eulerAngles = Vector3.zero; angleDirection = new Vector3(0, 90, 0); } private void Update() { transform.position = ClampPosition(); //Ç×»ó Æ÷Áö¼Ç Á¦¾È(VR·Î À̵¿½Ã¿¡µµ) //if (Keyboard.current.wasPressedThisFrame) //{ // isMove = !isMove; //} if (InputDevices.GetDeviceAtXRNode(XRNode.Head).isValid && !ray.activeSelf) { ray.SetActive(true); leftHand.SetActive(true); rightHand.SetActive(true); } else if (!InputDevices.GetDeviceAtXRNode(XRNode.Head).isValid && ray.activeSelf) { ray.SetActive(false); leftHand.SetActive(false); rightHand.SetActive(false); } if (!InputDevices.GetDeviceAtXRNode(XRNode.Head).isValid) { transform.position = new Vector3(transform.position.x, 0.3f, transform.position.z); cam.transform.position = new Vector3(transform.position.x, transform.position.y + 1.3176f, transform.position.z); if (Mouse.current.rightButton.ReadValue() == 1) { //cam.transform.position = Vector3.zero; //cam.transform.eulerAngles = Vector3.zero; MouseRotation(); KeyboardMove(); } } //player.OnClick_Button_Send(); } // ¸¶¿ì½º ȸÀü void MouseRotation() { float xRotateSize = Mouse.current.delta.x.ReadValue(); float yRotateSize = Mouse.current.delta.y.ReadValue(); angleDirection += new Vector3(-yRotateSize, xRotateSize, 0) * rotaveSpeed * Time.deltaTime; //xRotate = Mathf.Clamp(xRotate + xRotateSize, -80, 30); transform.eulerAngles = angleDirection; } // Űº¸µå À̵¿ void KeyboardMove() { transform.Translate(moveDirection * moveSpeed * Time.deltaTime); } // À̵¿ À§Ä¡ Á¦ÇÑ Vector3 ClampPosition() { return new Vector3( Mathf.Clamp(transform.position.x, -25f, 29f), Mathf.Clamp(transform.position.y, 0.002000809f, 3.5f), Mathf.Clamp(transform.position.z, -18f, 24f) ); } // Űº¸µå ÀÎDz °¨Áö void OnMove(InputValue value) { Vector2 input = value.Get(); if (input != null) { moveDirection = new Vector3(input.x, 0f, input.y); } else { moveDirection = Vector3.zero; } } }