• Unity RPC 链接


    using UnityEngine;
    using System.Collections;

    public class Menu : MonoBehaviour {

    public string IP = "127.0.0.1";
    public int Port = 25001;
    //public GameObject target;

    void OnGUI()
    {
    if (Network.peerType == NetworkPeerType.Disconnected)
    {
    if (GUI.Button(new Rect(100, 100, 100, 25), "Start Client"))
    {
    Network.Connect(IP, Port);
    }
    if (GUI.Button(new Rect(100, 125, 100, 25), "Start Server"))
    {
    Network.InitializeServer(10, Port);
    }
    }
    else
    {
    if (Network.peerType == NetworkPeerType.Client)
    {
    GUI.Label(new Rect(100, 100, 100, 25), "Client");

    if(GUI.Button(new Rect(100, 125, 110, 25), "Change Color"))
    {
    //NetworkView networkView = new NetworkView();
    //networkView.RPC("ChangeColor", RPCMode.All);
    GetComponent<NetworkView>().RPC("ChangeColor", RPCMode.All);
    Debug.Log("dsjakfj");

    }

    if (GUI.Button(new Rect(100, 150, 110, 25), "Logout"))
    {
    Network.Disconnect(250);
    }
    }

    if (Network.peerType == NetworkPeerType.Server)
    {
    GUI.Label(new Rect(100, 100, 100, 25), "Server");
    GUI.Label(new Rect(100, 125, 100, 25), "Connections:" + Network.connections.Length);

    if (GUI.Button(new Rect(100, 150, 100, 25), "Logout"))
    {
    Network.Disconnect(250);
    }
    }
    }
    }

    [RPC]
    void ChangeColor()
    {

    this.GetComponent<Renderer>().material.color = Color.green;
    }

    }

  • 相关阅读:
    软件工程(2018)第一次作业
    SQA计划
    再冲刺
    第三次冲刺
    第二次冲刺
    小组第一次冲刺
    团队合作初体验
    关于git的认识与想法
    我的第一篇博客
    SQA计划和系统测试规程
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/4813607.html
Copyright © 2020-2023  润新知