UNet基本知识略
一、场景创建空物体NetWorkManager添加脚本NetworkManager、NetworkManagerHUD
二、场景创建空物体SpawnPos添加脚本NetworkStartPosition
三、创建Player:NetworkPlayer (HTCInput例)填入NetworkManager
player.pngplayer.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);
}
}
}
网友评论