- Home /
UI Button Change Scene with Game Controller from a Mobile Device
Hello everyone,
I am trying to do user interface... i want to control my Pc Application which is made by unity with my phone application which is made by unity again... when i press the ui button i want to change the scene on pc application.
but there are several problems. i managed to connect server with my phone, but UI buttons not works.
i know there should be Networkserver and networkclient scripts..
here is NetworkServer code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine;
public class NetworkServerUI : MonoBehaviour {
private void OnGUI()
{
string ipaddress = Network.player.ipAddress;
GUI.Box(new Rect(10, Screen.height - 50, 100,50), ipaddress);
GUI.Label(new Rect(20, Screen.height - 35, 100, 20), "Status:" + NetworkServer.active);
GUI.Label(new Rect(20, Screen.height - 20, 100, 20), "Connected:" + NetworkServer.connections.Count);
}
// Use this for initialization
void Start () {
NetworkServer.Listen(25000);
}
// Update is called once per frame
void Update () {
}
}
Here is client code;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;
using UnityEngine;
public class NetworkClientUI : MonoBehaviour {
NetworkClient client;
void OnGUI()
{
string ipaddress = Network.player.ipAddress;
GUI.Box(new Rect(10, Screen.height - 50, 100, 50), ipaddress);
GUI.Label(new Rect(20, Screen.height - 30, 100, 20), "Status:" + client.isConnected);
if(!client.isConnected)
{
if(GUI.Button(new Rect(10,10,60,50),"Connect"))
{
Connect();
}
}
}
// Use this for initialization
void Start () {
client = new NetworkClient();
}
void Connect()
{
client.Connect("192.168.1.7", 25000);
}
// Update is called once per frame
void Update () {
}
}
here is change scene code;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeScene : MonoBehaviour {
public void ChangeToScene (string sceneName)
{
Application.LoadLevel(sceneName);
}
}
Please help me...
Your answer
Follow this Question
Related Questions
"Mouse Scrollwheel" on xbox 360controller 2 Answers
Limit number of face buttons being simultaneously held. 1 Answer
Question about moving an object technique 3 Answers
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers
How to change the walk speed of the FPSController from another script? 2 Answers