复习UNITY3D网络模块UNET

来源:互联网 发布:淘宝网蓝月亮洗衣液 编辑:程序博客网 时间:2024/05/19 02:17
 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;  //改变颜色
}
}
0 0
原创粉丝点击