复习UNITY3D网络模块UNET

xiaoxiao2021-02-27  390

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class PlayerController :NetworkBehaviour { public float traSpeed = 3;//移动的速度     public float rotSpeed = 120;//一秒旋转的角度     // Update is called once per frame     void Update () {        // isLocalPlayer 是 NetworkBehaviour 的内置属性         if (!isLocalPlayer) {   //如果不是本地客户端,就返回,不执行下面的操作                   return;         }         float h = Input.GetAxis("Horizontal");         float v = Input.GetAxis("Vertical");         transform.Translate(Vector3.forward * v * traSpeed * Time.deltaTime);    //朝某个方向移动         transform.Rotate(Vector3.up * h * rotSpeed * Time.deltaTime);  //围绕某轴旋转     } public override void OnStartLocalPlayer(){ GetComponent<MeshRenderer>().material.color = Color.red;  //改变颜色 } }
转载请注明原文地址: https://www.6miu.com/read-5815.html

最新回复(0)