您的位置:首页 > 理论基础 > 计算机网络

复习UNITY3D网络模块UNET

2017-05-04 17:56 162 查看
 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;  //改变颜色

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: