pong: fixed racket spawn position after reconnecting

This commit is contained in:
vis2k 2019-03-17 14:24:15 +01:00
parent 6d8d9f2998
commit 7e9b3efa7d
3 changed files with 32 additions and 27 deletions

View File

@ -200,7 +200,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 473997961}
- component: {fileID: 473997960}
m_Layer: 0
m_Name: RacketSpawnLeft
m_TagString: Untagged
@ -208,18 +207,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &473997960
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 473997959}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 41f84591ce72545258ea98cb7518d8b9, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &473997961
Transform:
m_ObjectHideFlags: 0
@ -722,7 +709,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1397990096}
- component: {fileID: 1397990095}
m_Layer: 0
m_Name: RacketSpawnRight
m_TagString: Untagged
@ -730,18 +716,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1397990095
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1397990094}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 41f84591ce72545258ea98cb7518d8b9, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1397990096
Transform:
m_ObjectHideFlags: 0
@ -954,7 +928,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1886246549}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8aab4c8111b7c411b9b92cf3dbc5bd4e, type: 3}
m_Script: {fileID: 11500000, guid: 0aa3018bb284840d6a6d0acee29ab098, type: 3}
m_Name:
m_EditorClassIdentifier:
dontDestroyOnLoad: 1
@ -972,6 +946,8 @@ MonoBehaviour:
autoCreatePlayer: 1
playerSpawnMethod: 1
spawnPrefabs: []
leftRacketSpawn: {fileID: 473997961}
rightRacketSpawn: {fileID: 1397990096}
--- !u!114 &1886246553
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -0,0 +1,18 @@
// custom NetworkManager that simply assigns the correct racket positions when
// spawning players. the built in RoundRobin spawn method wouldn't work after
// someone reconnects (both players would be on the same side).
using UnityEngine;
using Mirror;
public class NetworkManagerPong : NetworkManager
{
public Transform leftRacketSpawn;
public Transform rightRacketSpawn;
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage)
{
Transform start = numPlayers == 0 ? leftRacketSpawn : rightRacketSpawn;
GameObject player = Instantiate(playerPrefab, start.position, start.rotation);
NetworkServer.AddPlayerForConnection(conn, player);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0aa3018bb284840d6a6d0acee29ab098
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: