twighthero 发表于 2013-3-19 11:06

简单的网络代码

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();
}

}

leeliang1987 发表于 2017-3-31 20:58

很不错

zwqzjm 发表于 2017-3-31 21:30

楼主是超人

tiaoshiok1 发表于 2017-3-31 21:51

说的非常好

OnePage 发表于 2017-3-31 21:08

不错不错

1965285557 发表于 2017-3-31 21:05

LZ真是人才

zswnet 发表于 2017-4-9 08:57

楼主是超人

xiaohei 发表于 2017-4-9 08:49

顶顶多好

cgfr 发表于 2017-4-9 08:19

很好哦

cgfr 发表于 2017-4-9 08:48

不错不错
页: [1] 2 3 4 5
查看完整版本: 简单的网络代码