Moving to flex, Hoping it would fix platform
This commit is contained in:
46
Assets/Scripts/Door.cs
Normal file
46
Assets/Scripts/Door.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Door : MonoBehaviour
|
||||
{
|
||||
public SpriteRenderer openDoorSprite;
|
||||
public bool locked;
|
||||
|
||||
void Start(){
|
||||
if(!locked){
|
||||
openDoorSprite.color = Color.black;
|
||||
}
|
||||
}
|
||||
|
||||
public void unlock(){
|
||||
locked=false;
|
||||
openDoorSprite.color = Color.black;
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
Debug.Log(col.gameObject.name + " Entered");
|
||||
NetPlayer playerObject = col.GetComponent<NetPlayer>();
|
||||
if(!locked&& playerObject!=null){
|
||||
if(playerObject.isLocalPlayer){
|
||||
col.GetComponent<PlayerController>().inDoor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D col){
|
||||
Debug.Log(col.gameObject.name + " Exited");
|
||||
NetPlayer playerObject = col.GetComponent<NetPlayer>();
|
||||
if(!locked&& playerObject!=null){
|
||||
if(playerObject.isLocalPlayer){
|
||||
col.GetComponent<PlayerController>().inDoor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Door.cs.meta
Normal file
11
Assets/Scripts/Door.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83130d81d669a3e0cb774960d0a3c596
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -16,6 +16,7 @@ public class InputPresetData{
|
||||
public KeyCode leftInput;
|
||||
public KeyCode rightInput;
|
||||
public KeyCode jumpInput;
|
||||
public KeyCode interactingKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +48,7 @@ public static class InputManager{
|
||||
m_data.leftInput = KeyCode.A;
|
||||
m_data.rightInput = KeyCode.D;
|
||||
m_data.jumpInput = KeyCode.Space;
|
||||
m_data.interactingKey=KeyCode.W;
|
||||
|
||||
PlayerPrefs.SetString("inputSettings", JsonUtility.ToJson(m_data));
|
||||
PlayerPrefs.Save();
|
||||
|
||||
85
Assets/Scripts/Lobby.cs
Normal file
85
Assets/Scripts/Lobby.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class Lobby : NetworkBehaviour
|
||||
{
|
||||
[SyncVar]
|
||||
public int playerCount;
|
||||
[SyncVar]
|
||||
public string serverName;
|
||||
[SyncVar(hook = nameof(OnMetadataChanged))]
|
||||
public string serverMetadata;
|
||||
public string nextSceneName;
|
||||
void OnMetadataChanged(string oldValue, string newValue){
|
||||
SceneData.metadata = JsonUtility.FromJson<ServerMetadata>(newValue);
|
||||
}
|
||||
|
||||
public Text lobbyNameText;
|
||||
public Text playerCountTxt;
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
if(isServer){
|
||||
serverName = FindObjectOfType<LightReflectiveMirror.LightReflectiveMirrorTransport>().serverName;
|
||||
serverMetadata = FindObjectOfType<LightReflectiveMirror.LightReflectiveMirrorTransport>().extraServerData;
|
||||
}
|
||||
|
||||
lobbyNameText.text = serverName;
|
||||
SceneData.metadata = JsonUtility.FromJson<ServerMetadata>(serverMetadata);
|
||||
playerCountTxt.text = playerCount+"/" + SceneData.metadata.maxPlayerCount;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
public int[] playlist = new int[2]{1,2};
|
||||
public int curSceneInd=0;
|
||||
void Update()
|
||||
{
|
||||
if(playerCountTxt!=null){
|
||||
playerCountTxt.text = playerCount + "/ " + SceneData.metadata.maxPlayerCount;
|
||||
}
|
||||
if(!isServer){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NetPlayer[] netPlayers = FindObjectsOfType<NetPlayer>();
|
||||
playerCount = netPlayers.Length;
|
||||
if(playerCount < 1){return;}
|
||||
bool allInside =true;
|
||||
foreach(NetPlayer netPlayer in netPlayers){
|
||||
if(!netPlayer.insideDoor){allInside = false;break;}
|
||||
}
|
||||
|
||||
if(allInside){
|
||||
//Move onto next level
|
||||
if(curSceneInd < playlist.Length -1){
|
||||
curSceneInd++;
|
||||
nextSceneName = SceneManager.GetSceneByBuildIndex(playlist[curSceneInd]).name;
|
||||
}else{
|
||||
nextSceneName ="SampleScene";
|
||||
curSceneInd=0;
|
||||
}
|
||||
RpcNextLevel(playlist[curSceneInd]);
|
||||
changeScene(playlist[curSceneInd]);
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcNextLevel(int levelName){
|
||||
changeScene(levelName);
|
||||
}
|
||||
|
||||
void changeScene(int levelName){
|
||||
SceneData.localPlayer.GetComponent<PlayerController>().insideDoor=false;
|
||||
SceneData.localPlayer.GetComponent<NetPlayer>().CallChangeInsideDoor(false);
|
||||
|
||||
LoadingScreen.instance.alreadyConnected=true;
|
||||
LoadingScreen.instance.sceneName=null;
|
||||
LoadingScreen.instance.sceneIndex = levelName;
|
||||
LoadingScreen.instance.load();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lobby.cs.meta
Normal file
11
Assets/Scripts/Lobby.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e61f23073e4aea54ab53fc45e3c502a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -16,13 +16,15 @@ public class MainmenuController : MonoBehaviour
|
||||
public LightReflectiveMirrorTransport _LRM;
|
||||
public Toggle isPublic;
|
||||
public InputField serverNameInput;
|
||||
public Slider maxPlayerCount;
|
||||
void Start()
|
||||
{
|
||||
|
||||
_LRM = (LightReflectiveMirrorTransport)Transport.activeTransport;
|
||||
_LRM.serverListUpdated.AddListener(ServerListUpdate);
|
||||
_LRM.connectedToRelay.AddListener(refreshServers);
|
||||
// serverNameInput.text = usernameTxt.text + "'s Server";
|
||||
usernameTxt.text = PlayerPrefs.GetString("username");
|
||||
serverNameInput.text = usernameTxt.text + "'s Server";
|
||||
// refreshServers();
|
||||
}
|
||||
|
||||
@@ -54,7 +56,6 @@ public class MainmenuController : MonoBehaviour
|
||||
//clear all entries
|
||||
Debug.Log("it works");
|
||||
foreach(Transform t in scrollParent) { Destroy(t.gameObject); }
|
||||
bool b1 = false;
|
||||
for (int i =0; i < _LRM.relayServerList.Count; i++)
|
||||
{
|
||||
//int mapId = int.Parse(_LRM.relayServerList[i].serverName.Substring(0, 1));
|
||||
@@ -62,11 +63,7 @@ public class MainmenuController : MonoBehaviour
|
||||
go.transform.GetChild(0).GetComponent<Text>().text = _LRM.relayServerList[i].serverName;
|
||||
go.transform.GetChild(1).GetComponent<Text>().text = _LRM.relayServerList[i].currentPlayers + "/" + _LRM.relayServerList[i].maxPlayers;
|
||||
go.GetComponentInChildren<Button>().onClick.AddListener(() => { joinServer(_LRM.relayServerList[i-1].serverId.ToString()); });
|
||||
if (!b1)
|
||||
{
|
||||
go.GetComponent<Image>().color = Color.grey;
|
||||
b1 = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
scrollParent.GetComponent<RectTransform>().sizeDelta = new Vector2(scrollParent.GetComponent<RectTransform>().sizeDelta.x, heightPerRow *(_LRM.relayServerList.Count+1));
|
||||
@@ -86,28 +83,43 @@ public class MainmenuController : MonoBehaviour
|
||||
|
||||
public void joinServer()
|
||||
{
|
||||
FindObjectOfType<loadingScreen>().serverName = _LRM.relayServerList[curSelected].serverId.ToString();
|
||||
LoadingScreen.instance.serverName = _LRM.relayServerList[curSelected].serverId.ToString();
|
||||
|
||||
FindObjectOfType<loadingScreen>().load();
|
||||
LoadingScreen.instance.load();
|
||||
}
|
||||
public void joinServer(string serverName)
|
||||
{
|
||||
FindObjectOfType<loadingScreen>().serverName = serverName;
|
||||
FindObjectOfType<loadingScreen>().sceneName= "SampleScene";
|
||||
FindObjectOfType<loadingScreen>().isHost=false;
|
||||
LoadingScreen.instance.serverName = serverName;
|
||||
LoadingScreen.instance.sceneName= "SampleScene";
|
||||
LoadingScreen.instance.isHost=false;
|
||||
LoadingScreen.instance.alreadyConnected=false;
|
||||
|
||||
FindObjectOfType<loadingScreen>().load();
|
||||
LoadingScreen.instance.load();
|
||||
}
|
||||
|
||||
public void hostClicked()
|
||||
{
|
||||
if (serverNameInput.text.Length > 3)
|
||||
{
|
||||
FindObjectOfType<loadingScreen>().serverName = serverNameInput.text;
|
||||
FindObjectOfType<loadingScreen>().sceneName= "SampleScene";
|
||||
|
||||
FindObjectOfType<loadingScreen>().isPublic = isPublic.isOn;
|
||||
FindObjectOfType<loadingScreen>().load();
|
||||
LoadingScreen.instance.serverName = serverNameInput.text;
|
||||
LoadingScreen.instance.sceneName= "SampleScene";
|
||||
LoadingScreen.instance.isPublic = isPublic.isOn;
|
||||
LoadingScreen.instance.alreadyConnected=false;
|
||||
LoadingScreen.instance.isHost=true;
|
||||
ServerMetadata metadata = new ServerMetadata();
|
||||
metadata.maxPlayerCount = (int)maxPlayerCount.value;
|
||||
LoadingScreen.instance.serverMetadata = JsonUtility.ToJson(metadata);
|
||||
LoadingScreen.instance.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class ServerMetadata{
|
||||
public int maxPlayerCount;
|
||||
|
||||
public ServerMetadata(){
|
||||
maxPlayerCount = 0;
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,118 @@ public class NetPlayer : NetworkBehaviour
|
||||
{
|
||||
|
||||
public Behaviour[] LocalComponents;
|
||||
|
||||
public SpriteRenderer characterSprite;
|
||||
[SyncVar]
|
||||
public bool insideDoor;
|
||||
public LayerMask friendLayer;
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
if(!isLocalPlayer){
|
||||
gameObject.layer = LayerMask.NameToLayer("Friend");
|
||||
//GetComponent<BoxCollider2D>().size = new Vector2(GetComponent<BoxCollider2D>().size.x/2f,GetComponent<BoxCollider2D>().size.y);
|
||||
foreach(Behaviour localComponent in LocalComponents){
|
||||
localComponent.enabled=false;
|
||||
}
|
||||
}
|
||||
if(isLocalPlayer){
|
||||
SceneData.localPlayer = gameObject;
|
||||
if(SceneData.netSceneData==null){Debug.Log("Scene Data is not init yet");}else{
|
||||
transform.position = SceneData.netSceneData.spawnPoint.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
public void ReturnToSpawn(){
|
||||
if(isLocalPlayer){
|
||||
StartCoroutine(returnToSpawn());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator returnToSpawn(){
|
||||
while(SceneData.netSceneData==null){
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
while(SceneData.netSceneData.spawnPoint==null){
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
transform.position = SceneData.netSceneData.spawnPoint.position;
|
||||
|
||||
}
|
||||
public Transform frndTrans;
|
||||
bool oldFlipVal = false;
|
||||
|
||||
Transform oldFriendVal;
|
||||
float oldFriendX;
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(!isLocalPlayer){return;}
|
||||
frndTrans = getOnFriend();
|
||||
// if(oldFriendVal!=frndTrans){//got on someones head, or got off
|
||||
// if(oldFriendVal==null && frndTrans!=null){//got on
|
||||
// oldFriendX = frndTrans.position.x;
|
||||
// oldFriendVal = frndTrans;
|
||||
// }else{//got off
|
||||
// oldFriendX = 0;
|
||||
// oldFriendVal = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(oldFriendVal!=null){
|
||||
// transform.Translate(new Vector2(frndTrans.position.x - oldFriendX,0));
|
||||
// }
|
||||
|
||||
if(oldFlipVal != characterSprite.flipX){
|
||||
if(isServer){
|
||||
RpcFlipX(characterSprite.flipX);
|
||||
}else{
|
||||
CmdFlipX(characterSprite.flipX);
|
||||
}
|
||||
oldFlipVal=characterSprite.flipX;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!isServer){return;}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdFlipX(bool value){
|
||||
FlipX(value);
|
||||
RpcFlipX(value);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcFlipX(bool value){
|
||||
if(!isLocalPlayer)FlipX(value);
|
||||
}
|
||||
|
||||
void FlipX(bool value){
|
||||
characterSprite.flipX = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void CallChangeInsideDoor(bool value){
|
||||
if(isServer){
|
||||
insideDoor=value;
|
||||
}else{
|
||||
CmdChangeInsideDoor(value);
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
void CmdChangeInsideDoor(bool value){
|
||||
insideDoor=value;
|
||||
}
|
||||
|
||||
|
||||
public Transform getOnFriend()
|
||||
{
|
||||
Transform friend =null;
|
||||
//return (Physics2D.Linecast(transform.position, groundChecker.position, groundLayerMask));
|
||||
Collider2D col = GetComponentInChildren<Collider2D>();
|
||||
RaycastHit2D hit = Physics2D.BoxCast(col.bounds.center, new Vector2(col.bounds.size.x - (col.bounds.size.x / 5f), col.bounds.size.y), 0, Vector2.down, 0.1f, friendLayer);
|
||||
friend = (hit) ? hit.collider.transform : null;
|
||||
return friend;
|
||||
}
|
||||
}
|
||||
|
||||
21
Assets/Scripts/NetSceneData.cs
Normal file
21
Assets/Scripts/NetSceneData.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class NetSceneData : MonoBehaviour
|
||||
{
|
||||
public Transform spawnPoint;
|
||||
public Transform doorExit;
|
||||
public Door door;
|
||||
void Awake()
|
||||
{
|
||||
SceneData.netSceneData = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SceneData{
|
||||
public static NetSceneData netSceneData;
|
||||
public static ServerMetadata metadata;
|
||||
public static GameObject localPlayer;
|
||||
}
|
||||
11
Assets/Scripts/NetSceneData.cs.meta
Normal file
11
Assets/Scripts/NetSceneData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 176b9539293f58d65a001ed701f1959d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -23,6 +23,9 @@ public class PlayerController : NetworkBehaviour
|
||||
public AudioClip jumpSFX;
|
||||
float jumpT = 0;
|
||||
public bool listenToInput = true;
|
||||
public bool inDoor = false;
|
||||
public bool insideDoor = false;
|
||||
bool enteringDoor = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -75,6 +78,18 @@ public class PlayerController : NetworkBehaviour
|
||||
if (Input.GetKey(InputManager.data().leftInput)) { HorizontalAxis = -1; } else if (Input.GetKey(InputManager.data().rightInput)) { HorizontalAxis = 1; }
|
||||
// if (GameManager.isPaused) { HorizontalAxis = 0; }
|
||||
//Move according to input
|
||||
|
||||
//Exit the door
|
||||
if(enteringDoor && !Input.GetKey(InputManager.data().interactingKey)){
|
||||
enteringDoor=false;
|
||||
}
|
||||
if(insideDoor && !enteringDoor && Input.GetKey(InputManager.data().interactingKey)){
|
||||
Debug.Log("Exiting door");
|
||||
transform.position = SceneData.netSceneData.door.transform.position;
|
||||
insideDoor=false;
|
||||
enteringDoor=true;
|
||||
if(GetComponent<NetPlayer>()!=null){GetComponent<NetPlayer>().CallChangeInsideDoor(insideDoor);}
|
||||
}
|
||||
if (listenToInput)
|
||||
{
|
||||
if (isGrounded)
|
||||
@@ -90,7 +105,19 @@ public class PlayerController : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//Enter the door
|
||||
if(inDoor && Input.GetKey(InputManager.data().interactingKey) && !enteringDoor){
|
||||
if(SceneData.netSceneData.doorExit!=null){
|
||||
Debug.Log("Entering door");
|
||||
transform.position = SceneData.netSceneData.doorExit.position;
|
||||
insideDoor = true;
|
||||
enteringDoor=true;
|
||||
if(GetComponent<NetPlayer>()!=null){GetComponent<NetPlayer>().CallChangeInsideDoor(insideDoor);}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isSwimming || inWater) { moveInput = moveInput / 2f; }
|
||||
//Update moving value on Animation
|
||||
animator.SetBool("moving", (moveInput != 0));
|
||||
@@ -109,6 +136,11 @@ public class PlayerController : NetworkBehaviour
|
||||
|
||||
|
||||
//Apply moving input to player
|
||||
if(GetComponent<NetPlayer>()!=null){
|
||||
if(GetComponent<NetPlayer>().frndTrans!=null){
|
||||
rigidbody.velocity = GetComponent<NetPlayer>().frndTrans.GetComponent<Rigidbody2D>().velocity;
|
||||
}
|
||||
}
|
||||
rigidbody.transform.Translate(new Vector2(moveSpeed * moveInput, 0));
|
||||
|
||||
|
||||
@@ -138,6 +170,7 @@ public class PlayerController : NetworkBehaviour
|
||||
_isSwimming = inWater;
|
||||
|
||||
}
|
||||
|
||||
bool b;
|
||||
bool _isSwimming;
|
||||
public bool waterBoost;
|
||||
@@ -183,6 +216,8 @@ public class PlayerController : NetworkBehaviour
|
||||
Collider2D col = GetComponentInChildren<Collider2D>();
|
||||
return (Physics2D.BoxCast(col.bounds.center, new Vector2(col.bounds.size.x - (col.bounds.size.x / 5f), col.bounds.size.y), 0, Vector2.down, 0.1f, groundLayerMask));
|
||||
}
|
||||
|
||||
|
||||
// public bool getInWater(){Collider2D col = GetComponentInChildren<Collider2D>();
|
||||
// return (Physics2D.BoxCast(col.bounds.center, new Vector2(col.bounds.size.x - (col.bounds.size.x / 5f), col.bounds.size.y), 0, Vector2.down, 0.1f, waterLayerMask));
|
||||
// }
|
||||
|
||||
@@ -11,6 +11,7 @@ using UnityEngine.UI;
|
||||
public class loadingScreen : MonoBehaviour
|
||||
{
|
||||
public string sceneName;
|
||||
public int sceneIndex;
|
||||
public RectTransform loadingWheel;
|
||||
public RectTransform loadingProgress;
|
||||
CanvasGroup canvasGroup;
|
||||
@@ -29,6 +30,7 @@ public class loadingScreen : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
LoadingScreen.instance=this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
|
||||
@@ -69,26 +71,37 @@ public class loadingScreen : MonoBehaviour
|
||||
loading = true;
|
||||
loadingProgress.sizeDelta = new Vector2(0, loadingProgress.sizeDelta.y);
|
||||
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
|
||||
loadingOperation = SceneManager.LoadSceneAsync(sceneName);
|
||||
if(sceneName != null){
|
||||
loadingOperation = SceneManager.LoadSceneAsync(sceneName);
|
||||
}else{
|
||||
loadingOperation = SceneManager.LoadSceneAsync(sceneIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
|
||||
{
|
||||
if (loading)
|
||||
hide();
|
||||
if (loading && !alreadyConnected)
|
||||
{
|
||||
// hide();
|
||||
if(isHost){host();}else{join();}
|
||||
|
||||
loading = false;
|
||||
loading = false;
|
||||
}
|
||||
if(alreadyConnected){
|
||||
// Debug.Log()
|
||||
SceneData.netSceneData = FindObjectOfType<NetSceneData>();
|
||||
SceneData.localPlayer.GetComponent<NetPlayer>().ReturnToSpawn();
|
||||
|
||||
}
|
||||
}
|
||||
public bool alreadyConnected= false;
|
||||
public string serverName;
|
||||
public bool isPublic;
|
||||
public string serverMetadata;
|
||||
|
||||
void host()
|
||||
{
|
||||
_LRM.serverName = serverName;
|
||||
_LRM.extraServerData = sceneName;
|
||||
_LRM.extraServerData = serverMetadata;
|
||||
_LRM.isPublicServer = isPublic;
|
||||
|
||||
_LRM.ServerStart();
|
||||
@@ -101,3 +114,8 @@ public class loadingScreen : MonoBehaviour
|
||||
NetworkManager.singleton.StartClient();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class LoadingScreen{
|
||||
public static loadingScreen instance;
|
||||
}
|
||||
|
||||
36
Assets/Scripts/login.cs
Normal file
36
Assets/Scripts/login.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class login : MonoBehaviour
|
||||
{
|
||||
public InputField nameInput;
|
||||
public Button loginBtn;
|
||||
void Start()
|
||||
{
|
||||
loginBtn.interactable = false;
|
||||
if (PlayerPrefs.HasKey("username") && PlayerPrefs.GetString("username").Length > 3)
|
||||
{
|
||||
SceneManager.LoadScene("MainMenu");
|
||||
return;
|
||||
}
|
||||
|
||||
nameInput.onValueChanged.AddListener(OnNameinputChange);
|
||||
}
|
||||
|
||||
|
||||
void OnNameinputChange(string value)
|
||||
{
|
||||
loginBtn.interactable = (value.Length > 3);
|
||||
}
|
||||
|
||||
public void Login(){
|
||||
if(nameInput.text.Length <=3){return;}
|
||||
|
||||
PlayerPrefs.SetString("username", nameInput.text);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
SceneManager.LoadScene("MainMenu");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/login.cs.meta
Normal file
11
Assets/Scripts/login.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb602c1a35483c66e97589f39f2fbf49
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user