How can i make it public

Hey, I have a script problem, when I create a clan that only appears for the creator. How do I make the panel public for everyone, and when creating a new clan that everyone sees it

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Clan : MonoBehaviour
{
    public GameObject ClanContainer;
    public GameObject ClanMembersContainer;
    public GameObject ClanDescriptionContainer;

    public GameObject ClanListPrefab;
    public GameObject ClanMembersPrefab;
    public GameObject ClanDescriptionPrefab;

    public InputField ClanName;
    public InputField ClanDescripiton;
    public GameObject ClanPanel;

    public GameObject OpenCreateClan;
    public GameObject Promote;
    public GameObject Demote;
    public GameObject[] cDescripition;
    public GameObject[] cMember;
    int index = 0;
    List<string> ClanList = new List<string>();
    enum Rank
    {
        Trial,
        Member,
        Leader,
        Founder
    }
    public void CreateClan()
    {
        if (ClanName.text == "Admins" || ClanName.text == "Staff")
        {
            Debug.Log("You can't Create clan with this name");
        }
        else if (ClanList.Contains(ClanName.text))
        {
            Debug.Log("Exist clan name");
        }
        else if (ClanName.text == "")
        {
            Debug.Log("Plese write clan name");
        }
        else
        {
            ClanList.Add(ClanName.text);
            GameObject cClan = Instantiate(ClanListPrefab, ClanContainer.transform) as GameObject;
            cClan.transform.Find("ClanName").GetComponentInChildren<Text>().text = ClanName.text;
            cClan.GetComponentInChildren<Text>().text = (index + 1).ToString();

            int copyOfIndex = index;

            index++;
            cClan.GetComponent<Button>().onClick.AddListener(

            () =>
            {
                foreach (GameObject go in cDescripition)
                    go.SetActive(false);

                if (cDescripition[copyOfIndex])
                    cDescripition[copyOfIndex].SetActive(true);

                foreach (GameObject go in cMember)
                    go.SetActive(false);

                if (cMember[copyOfIndex])
                    cMember[copyOfIndex].SetActive(true);

            }
            );
            GameObject Descripition = Instantiate(ClanDescriptionPrefab, ClanDescriptionContainer.transform) as GameObject;
            Descripition.transform.Find("ClanName").GetComponentInChildren<Text>().text = ClanName.text;
            Descripition.transform.Find("ClanDescription").GetComponentInChildren<Text>().text = ClanDescripiton.text;

            GameObject ClanMember = Instantiate(ClanMembersPrefab, ClanMembersContainer.transform) as GameObject;
            Rank myRank = Rank.Founder;
            ClanMember.transform.Find("MemberName").GetComponentInChildren<Text>().text = "Ibrahim";
            ClanMember.transform.Find("MemberRank").GetComponentInChildren<Text>().text = myRank.ToString();

            ClanPanel.SetActive(true);
              OpenCreateClan.SetActive(false);

            cDescripition = new GameObject[ClanDescriptionContainer.transform.childCount];
            for (int i = 0; i < ClanDescriptionContainer.transform.childCount; i++)
                cDescripition[i] = ClanDescriptionContainer.transform.GetChild(i).gameObject;

            cMember = new GameObject[ClanMembersContainer.transform.childCount];
            for (int i = 0; i < ClanMembersContainer.transform.childCount; i++)
                cMember[i] = ClanMembersContainer.transform.GetChild(i).gameObject;

            foreach (GameObject go in cDescripition)
                go.SetActive(false);

            foreach (GameObject go in cMember)
                go.SetActive(false);

            Promote.GetComponent<Button>().onClick.AddListener(
            () =>
            {
                Rank newRank = (Rank)((int)myRank++);
                if ((int)newRank > 3)
                {
                    return;
                }
                else
                {
                    if (myRank == Rank.Founder)
                    {
                        ClanMember.transform.Find("MemberRank").GetComponentInChildren<Text>().text = newRank.ToString();
                        return;

                    }
                }
            }
            );
            Demote.GetComponent<Button>().onClick.AddListener(
            () =>
            {
                Rank newRank = (Rank)((int)myRank--);
                if ((int)newRank < 0)
                {
                    return;
                }
                else
                {
                    if (myRank == Rank.Founder)
                    {
                        ClanMember.transform.Find("MemberRank").GetComponentInChildren<Text>().text = newRank.ToString();

                    }
                    Debug.Log("You don't have permission to access");
                }
            }
            );
        }
    }
}

What does ‘everybody’ mean?

If you mean the world, that’s an advertising problem.

If you mean your team, that’s a team communication or source control problem.

If you mean the network of people currently playing in your game, that’s a networking problem, and I don’t see any networking code above.

2 Likes

@Kurt-Dekker

Client

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using UnityEngine;
using UnityEngine.UI;

public class Clan : MonoBehaviour
{
    public GameObject ClanContainer;
    public GameObject ClanMembersContainer;
    public GameObject ClanDescriptionContainer;

    public GameObject ClanListPrefab;
    public GameObject ClanMembersPrefab;
    public GameObject ClanDescriptionPrefab;

    public InputField ClanName;
    public InputField ClanDescripiton;
    public GameObject ClanPanel;

    public GameObject OpenCreateClan;
    public GameObject Promote;
    public GameObject Demote;
    public GameObject[] cDescripition;
    public GameObject[] cMember;
    int index = 0;
    private bool SocketReady;
    private TcpClient socket;
    private NetworkStream stream;
    private StreamWriter writer;
    private StreamReader reader;
    List<string> ClanList = new List<string>();
    enum Rank
    {
        Trial,
        Member,
        Leader,
        Founder
    }
    public void ConntectToServer()
    {
        if (SocketReady)
            return;

        string host = "127.0.0.1";
        int port = 6321;
        try
        {
            socket = new TcpClient(host, port);
            stream = socket.GetStream();
            writer = new StreamWriter(stream);
            reader = new StreamReader(stream);
            SocketReady = true;
        }
        catch (Exception e)
        {
            Debug.Log("socket error" + e.Message);
        }
    }
    public void CreateClan()
    {
        if (ClanName.text == "Admins" || ClanName.text == "Staff")
        {
            Debug.Log("You can't Create clan with this name");
        }
        else if (ClanList.Contains(ClanName.text))
        {
            Debug.Log("Exist clan name");
        }
        else if (ClanName.text == "")
        {
            Debug.Log("Plese write clan name");
        }
        else
        {
            ClanList.Add(ClanName.text);
            GameObject cClan = Instantiate(ClanListPrefab, ClanContainer.transform) as GameObject;
            cClan.transform.Find("ClanName").GetComponentInChildren<Text>().text = ClanName.text;
            cClan.GetComponentInChildren<Text>().text = (index + 1).ToString();

            int copyOfIndex = index;

            index++;
            cClan.GetComponent<Button>().onClick.AddListener(

            () =>
            {
                foreach (GameObject go in cDescripition)
                    go.SetActive(false);

                if (cDescripition[copyOfIndex])
                    cDescripition[copyOfIndex].SetActive(true);

                foreach (GameObject go in cMember)
                    go.SetActive(false);

                if (cMember[copyOfIndex])
                    cMember[copyOfIndex].SetActive(true);

            }
            );
            GameObject Descripition = Instantiate(ClanDescriptionPrefab, ClanDescriptionContainer.transform) as GameObject;
            Descripition.transform.Find("ClanName").GetComponentInChildren<Text>().text = ClanName.text;
            Descripition.transform.Find("ClanDescription").GetComponentInChildren<Text>().text = ClanDescripiton.text;

            GameObject ClanMember = Instantiate(ClanMembersPrefab, ClanMembersContainer.transform) as GameObject;
            Rank myRank = Rank.Founder;
            ClanMember.transform.Find("MemberName").GetComponentInChildren<Text>().text = "Ibrahim";
            ClanMember.transform.Find("MemberRank").GetComponentInChildren<Text>().text = myRank.ToString();

            ClanPanel.SetActive(true);
              OpenCreateClan.SetActive(false);

            cDescripition = new GameObject[ClanDescriptionContainer.transform.childCount];
            for (int i = 0; i < ClanDescriptionContainer.transform.childCount; i++)
                cDescripition[i] = ClanDescriptionContainer.transform.GetChild(i).gameObject;

            cMember = new GameObject[ClanMembersContainer.transform.childCount];
            for (int i = 0; i < ClanMembersContainer.transform.childCount; i++)
                cMember[i] = ClanMembersContainer.transform.GetChild(i).gameObject;

            foreach (GameObject go in cDescripition)
                go.SetActive(false);

            foreach (GameObject go in cMember)
                go.SetActive(false);

            Promote.GetComponent<Button>().onClick.AddListener(
            () =>
            {
                Rank newRank = (Rank)((int)myRank++);
                if ((int)newRank > 3)
                {
                    return;
                }
                else
                {
                    if (myRank == Rank.Founder)
                    {
                        ClanMember.transform.Find("MemberRank").GetComponentInChildren<Text>().text = newRank.ToString();
                        return;

                    }
                }
            }
            );
            Demote.GetComponent<Button>().onClick.AddListener(
            () =>
            {
                Rank newRank = (Rank)((int)myRank--);
                if ((int)newRank < 0)
                {
                    return;
                }
                else
                {
                    if (myRank == Rank.Founder)
                    {
                        ClanMember.transform.Find("MemberRank").GetComponentInChildren<Text>().text = newRank.ToString();

                    }
                    Debug.Log("You don't have permission to access");
                }
            }
            );
        }
    }
}

Server

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net.Sockets;
using System;
using System.Net;
using System.IO;

public class Server : MonoBehaviour
{
    private List<ServerClient> clients;
    private List<ServerClient> disconnectList;

    public int port = 6321;
    private TcpListener server;
    private bool serverStarted;
    private void Start()
    {
        clients = new List<ServerClient>();
        disconnectList = new List<ServerClient>();

        try
        {
            server = new TcpListener(IPAddress.Any, port);
            server.Start();
            StartLestning();
            serverStarted = true;
            Debug.Log("Server has been started on port " + port.ToString());
        }
        catch (Exception e)
        {
            Debug.Log("Socket error:" + e.Message);
        }
    }
    private void Update()
    {
        if (!serverStarted)
            return;


        foreach (ServerClient c in clients)
        {
            if (!IsConnected(c.tcp))
            {
                c.tcp.Close();
                disconnectList.Add(c);
                continue;

            }
            else
            {
                NetworkStream s = c.tcp.GetStream();
                StreamReader reader = new StreamReader(s, true);
                if (s.DataAvailable)
                {
                    string data = reader.ReadLine();
                    if (data != null)
                        OninComingData(c, data);
                }

            }
        }
            for (int i = 0; i < disconnectList.Count -1; i++)
        {
            BroadCast(disconnectList[i].clientName + " has disconnected", clients);
            clients.Remove(disconnectList[i]);
            disconnectList.RemoveAt(i);
        }
    }
    private void StartLestning()
    {
        server.BeginAcceptTcpClient(AcceptTcpClient, server);
    }
    private bool IsConnected(TcpClient c)
    {
        try
        {
            if (c != null && c.Client != null && c.Client.Connected)
            {
                if (c.Client.Poll(0, SelectMode.SelectRead))
                {
                    return !(c.Client.Receive(new byte[1], SocketFlags.Peek) == 0);
                }
                return true;
            }
            return false;
        }
        catch
        {
            return false;
        }
    }
    private void AcceptTcpClient(IAsyncResult ar)
    {
        TcpListener listener = (TcpListener)ar.AsyncState;
        clients.Add(new ServerClient(listener.EndAcceptTcpClient(ar)));
        StartLestning();

        BroadCast("%NAME", new List<ServerClient>() { clients[clients.Count - 1] });

    }
    private void OninComingData(ServerClient c, string data)
    {
        if (data.Contains("&NAME"))
        {
            c.clientName = data.Split('|')[1];
            BroadCast(c.clientName + " Has connected",clients);
            return;
        }
        BroadCast(c.clientName + " : " + data,clients);
    }
    private void BroadCast(string data, List<ServerClient> cl)
    {
        foreach(ServerClient c in cl)
        {
            try
            {
                StreamWriter writer = new StreamWriter(c.tcp.GetStream());
                writer.WriteLine(data);
                writer.Flush();
            }
            catch(Exception e)
            {
                Debug.Log("Write error" + e.Message +"To client " + c.clientName);
            }
        }
    }
}


public class ServerClient
{
    public TcpClient tcp;
    public string clientName;

    public ServerClient(TcpClient ClientSockets)
    {
        clientName = "guest";
        tcp = ClientSockets;
    }
}