【发布时间】:2016-12-27 09:23:27
【问题描述】:
我想要做的是创建一个 3d 汽车游戏,其中敌车从前面来,你正在与你的敌人对抗,你的车现在可以向左或向右行驶,所有事情都可以在你的计算机/团结上运行(服务器)由您的 android 应用程序(客户端)控制。 我已经通过使用 RPC 在统一上创建了它,并且客户端和服务器都在统一上,但问题是我正在使用 android studio 构建一个 android 应用程序,因此如何将该应用程序与统一连接并开始它们之间的通信。
我在客户端和服务器端有 2 个按钮
客户端(当点击客户端连接并加载客户端屏幕时)
服务器(当点击服务器启动并加载服务器端屏幕时)
在客户端屏幕上 当点击播放按钮时,游戏在服务器端启动,它由我的客户端控制,左右两个按钮
我的主要 Uimanager 脚本写在下面,并附上了我的游戏图像,所以请帮助我,因为我在这个问题上卡住了大约一周enter image description here。
UiManager Script using UnityEngine; using System.Collections;
public class UiManager : MonoBehaviour {
// Use this for initialization
public GameObject car;
public CarController moveCar;
public NetworkView nView;
string level1;
void Start () {
nView = GetComponent<NetworkView>();
}
// Update is called once per frame
void Update () {
ClientLeft();
// networkView.RPC;
}
public void Pause()
{
if(Time.timeScale == 1)
{
Time.timeScale = 0;
}
else if(Time.timeScale == 0)
{
Time.timeScale = 1;
}
}
string ip = "127.0.0.1" ;
int portno = 25001;
public void Server()
{
Network.InitializeServer(10, portno);
if (Network.peerType == NetworkPeerType.Server)
{
Application.LoadLevel("Menu");
}
}
public void Client()
{
Network.Connect(ip, portno);
if(Network.peerType == NetworkPeerType.Client)
{
Application.LoadLevel("clientSide");
}
}
void OnConnectedToServer()
{
Application.LoadLevel("clientSide");
}
public void ClientPaly()
{
if (Network.peerType == NetworkPeerType.Client)
{
nView.RPC("Play", RPCMode.Server);
}
}
public void ClientLeft()
{
if (Network.peerType == NetworkPeerType.Client)
{
// nView.RPC("moveLeft", RPCMode.Server);
moveCar.moveLeft();
}
}
public void ClientRight()
{
if (Network.peerType == NetworkPeerType.Client)
{
nView.RPC("moveRight", RPCMode.Server);
}
}
[RPC]
public void Play()
{
Application.LoadLevel("Level1");
}
}
【问题讨论】:
标签: android android-studio unity3d network-programming connection