|
using UnityEngine;
using System.Collections;
public class Text_2 : MonoBehaviour {
enum State{
Tille,
Goming
}
public GameObject ball;
GameObject ball_2;
public string ipAdd="127.0.0.1";
public int port=12345;
State myState=State.Tille;
void Start () {
}
void Update () {
if(myState==State.Goming)
{
transform.LookAt(ball_2.transform);
ball_2.rigidbody.AddForce(Vector3.forward*Input.GetAxis("Vertical")*20f);
ball_2.rigidbody.AddForce(Vector3.right*Input.GetAxis("Horizontal")*20);
}
}
void OnGUI()
{
if(myState==State.Tille)
{
ipAdd=GUI.TextField(new Rect(10,40,200,20),ipAdd);
if(GUI.Button(new Rect(10,10,50,25),"Creet"))
{
Network.InitializeServer(32,port,false);
}
if(GUI.Button(new Rect(10,80,50,25),"Join"))
{
Network.Connect(ipAdd,port);
}
}
}
void InstantiateBall()
{
ball_2=Network.Instantiate(ball,new Vector3(0,0,0),Quaternion.identity,0)as GameObject;
myState=State.Goming;
}
void OnServerInitialized()
{
InstantiateBall();
}
void OnConnectedToServer()
{
InstantiateBall();
}
}
|
|