美文网首页工作生活
UnityVR+UNet多人在线

UnityVR+UNet多人在线

作者: 玄策丶 | 来源:发表于2019-07-02 15:17 被阅读0次

    UNet基本知识略

    一、场景创建空物体NetWorkManager添加脚本NetworkManager、NetworkManagerHUD

    二、场景创建空物体SpawnPos添加脚本NetworkStartPosition

    三、创建Player:NetworkPlayer (HTCInput例)填入NetworkManager

    player.png
    player.png
    添加脚本
    NetworkIdentity
    NetworkTransform
    NetworkTransformChild * 3(分别填入上图中Body、LeftHand、RightHand)
    localPlayerControl(下)
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;
    using InputTracking = UnityEngine.XR.InputTracking;
    using Node = UnityEngine.XR.XRNode;
    using HTC.UnityPlugin.Vive;
    public class localPlayerControl : NetworkBehaviour 
    {
        public GameObject CamRig;
        public Transform leftHand;
        public Transform rightHand;
        //public Camera leftEye;
        //public Camera rightEye;
        Vector3 pos;
        void Start () 
        {
            pos = transform.position;
        }
        void Update () 
        {
            if (!isLocalPlayer)
            {
                Destroy(CamRig);
            }
            else
            {
                //其他玩家进入时摄像机
                //if (leftEye.tag !="MainCamera")
                //{
                //    leftEye.tag = "MainCamera";
                //    leftEye.enabled = true;
                //}
                //if (rightEye.tag != "MainCamera")
                //{
                //    rightEye.tag = "MainCamera";
                //    rightEye.enabled = true;
                //}
                //手部位置
                leftHand.localRotation = InputTracking.GetLocalRotation(Node.LeftHand);
                rightHand.localRotation = InputTracking.GetLocalRotation(Node.RightHand);
                leftHand.localPosition = InputTracking.GetLocalPosition(Node.LeftHand);
                rightHand.localPosition = InputTracking.GetLocalPosition(Node.RightHand);
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:UnityVR+UNet多人在线

        本文链接:https://www.haomeiwen.com/subject/gtnzcctx.html