Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using FishNet.Object;
- public class Player : NetworkBehaviour
- {
- private Player[] players; //this is a card game where people create 'teams' then battle other players with them. This script
- //is just meant to spawn the teams initially.
- static public int playerNumber;
- public GameObject mainCamera;
- public override void OnStartClient()
- {
- base.OnStartClient();
- mainCamera = GameObject.Find("MainCamera");
- if (IsClientOnly)
- {
- mainCamera.transform.SetPositionAndRotation(new Vector3(0, 0, 189.9f), Quaternion.Euler(180, 0, 0));
- }
- if (IsOwner)
- {
- if (IsClientOnly)
- {
- playerNumber = 2;
- }
- else
- {
- playerNumber = 1;
- }
- }
- if (IsOwner && IsClientOnly) //tugboat is set up to allow only 2 players max
- {
- RpcServerGetTeam(); //this is called only when the second (final) player joins
- }
- }
- //right now, objects won't get deleted when connection breaks...but when I begin adding different scenes, I'll ensure that
- //when the connection breaks, the whole scene is reset.
- [ServerRpc]
- private void RpcServerGetTeam() //tell the server to tell each client to get their teams and resend them to the server
- {
- RpcClientGetTeam();
- }
- [ObserversRpc]
- private void RpcClientGetTeam()
- {
- players = FindObjectsOfType<Player>();
- foreach (Player player in players) //find both players in the scene
- {
- player.GetTeam();
- }
- }
- private TeamBuilder teambuilder;
- public void GetTeam()
- {
- if (IsOwner)
- {
- teambuilder = GameObject.Find("MiscScripts").GetComponent<TeamBuilder>();
- RpcServerSpawnTeam(teambuilder.MyTeam, IsClientOnly, LocalConnection);
- }
- }
- [ServerRpc]
- private void RpcServerSpawnTeam(GameObject[] myTeam, bool isClientOnly, FishNet.Connection.NetworkConnection ownerConnection)
- {
- GameObject nobCanvas = GameObject.Find("NobCanvas");
- GameObject[] teamSetup = new GameObject[6];
- int y;
- if (isClientOnly)
- {
- y = 1;
- }
- else
- {
- y = -1;
- }
- for (int i = 0; i < 6; i++)
- {
- teamSetup[i] = Instantiate(myTeam[i]);
- }
- teamSetup[0].transform.SetParent(nobCanvas.transform);
- teamSetup[0].transform.localPosition = new Vector2(-50, 320 * y);
- teamSetup[1].transform.SetParent(teamSetup[0].transform);
- teamSetup[1].transform.localPosition = new Vector2(220, 115.625f);
- teamSetup[2].transform.SetParent(teamSetup[0].transform);
- teamSetup[2].transform.localPosition = new Vector2(220, 0);
- teamSetup[3].transform.SetParent(nobCanvas.transform);
- teamSetup[3].transform.localPosition = new Vector2(550, 320 * y);
- teamSetup[4].transform.SetParent(teamSetup[3].transform);
- teamSetup[4].transform.localPosition = new Vector2(220, 115.625f);
- teamSetup[5].transform.SetParent(teamSetup[3].transform);
- teamSetup[5].transform.localPosition = new Vector2(220, 0);
- for (int i = 0; i < 6; i++)
- {
- teamSetup[i].transform.localScale = new Vector2(1, 1);
- ServerManager.Spawn(teamSetup[i], ownerConnection);
- }
- RpcClientSpawnTeam(teamSetup, y);
- }
- [ObserversRpc]
- private void RpcClientSpawnTeam(GameObject[] teamSetup, int y)
- {
- GameObject nobCanvas = GameObject.Find("NobCanvas");
- teamSetup[0].transform.SetParent(nobCanvas.transform);
- teamSetup[0].transform.localPosition = new Vector2(-50, 320 * y);
- teamSetup[1].transform.SetParent(teamSetup[0].transform);
- teamSetup[1].transform.localPosition = new Vector2(220, 115.625f);
- teamSetup[2].transform.SetParent(teamSetup[0].transform);
- teamSetup[2].transform.localPosition = new Vector2(220, 0);
- teamSetup[3].transform.SetParent(nobCanvas.transform);
- teamSetup[3].transform.localPosition = new Vector2(550, 320 * y);
- teamSetup[4].transform.SetParent(teamSetup[3].transform);
- teamSetup[4].transform.localPosition = new Vector2(220, 115.625f);
- teamSetup[5].transform.SetParent(teamSetup[3].transform);
- teamSetup[5].transform.localPosition = new Vector2(220, 0);
- for (int i = 0; i < 6; i++)
- {
- teamSetup[i].transform.localScale = new Vector2(1, 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement