找回密码
 立即注册
查看: 4001|回复: 45

[脚本] 简单的网络代码

[复制链接]
发表于 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();
}

}
发表于 2017-3-31 20:58 | 显示全部楼层
很不错
发表于 2017-3-31 21:30 | 显示全部楼层
楼主是超人
发表于 2017-3-31 21:51 | 显示全部楼层
说的非常好
发表于 2017-3-31 21:08 | 显示全部楼层
不错不错
发表于 2017-3-31 21:05 | 显示全部楼层
LZ真是人才
发表于 2017-4-9 08:57 | 显示全部楼层
楼主是超人
发表于 2017-4-9 08:49 | 显示全部楼层
顶顶多好
发表于 2017-4-9 08:19 | 显示全部楼层
很好哦
发表于 2017-4-9 08:48 | 显示全部楼层
不错不错
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-30 13:46 , Processed in 0.166753 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表