- Home /
unity 3d game which is control by an Android app
Dear All What i want to do is to create a 3d car game in which enemy car is coming from front and you are going against to your enemy and your car can just go toward left or right now every thing will work on your computer/unity(server) which is control by your android app(client). now i have just implemented this using RPC in unity but the problem is how to connect your server i unity with android app what i basically need is a code or something on which i can work and can get started i am using UiManager script in which server are created and client are connect.
screen 1 two button Client (when clicked client is connected and clienrside screen is loaded) server (when clicked server is started and serverside screen is loaded)
clientside screen three button play (when clicked game is started on server side) left (when clicked car go towards left) right (when clicked car go towards right)
serverside 1 button play (to play from serverside manually )
now when game is started and clicked on play from client side game started on server side but again both server and client and on unity but what i want is the server of unity and 1 client of android app and i can control my game with is
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");
}
}
my project is of 55 mb what's why i can;t upload it here