Skip to content

Commit

Permalink
Fix music not stopping on clients at end of level
Browse files Browse the repository at this point in the history
  • Loading branch information
plaidpants committed Feb 2, 2022
1 parent 096e9d0 commit 1fbedfd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
14 changes: 12 additions & 2 deletions Assets/NetworkManagerRocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ void SwitchScenes()
preparing = false;
}

void StopMusic()
{
RocketSphere[] players = FindObjectsOfType<RocketSphere>();

for (int i = 0; i < players.Length; i++)
{
// deactivate music all the ships on all clients
players[i].RpcStopMusic();
}
}

void Update()
{
if (RockSphere.count != lastCount)
Expand All @@ -58,8 +69,7 @@ void Update()

preparing = true;

// stop the music at the end of the level
Camera.main.transform.gameObject.GetComponent<AudioSource>().Stop();
StopMusic();

// wait 10 seconds before switching to the next level
Invoke("SwitchScenes", 10);
Expand Down
22 changes: 16 additions & 6 deletions Assets/RocketSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//ideas
// fixed wormhole between two depth levels
// hyperspace between two depth levels
// multi-player
// shield, use physics to bounce off rocks and other ships
// UFO
// radar circle indicating rocks, UFOs, enemy rockets around
// black holes/gravity
// make front transparent when in background
// bright light shots with lens flare
// readjust center point if head moves too far away from center
// add fade in and out of levels

//rockets, rocks and ray-guns
// stick man astronauts
Expand All @@ -24,8 +24,6 @@
// laser instead of shots will cut rocks om half instead of break them up in two.
// need to scale speed (ship and shot and rocks) by radius otherwise the outer layers get really fast

// When disconnecting from the server before leaving all clients generate a hyperspace sound to indicate you are leaving

public class RocketSphere : NetworkBehaviour
{
GameObject rocket;
Expand Down Expand Up @@ -55,7 +53,7 @@ void OnDestroy()
{
Destroy(cachedMaterial);
}

public override void OnStartServer()
{
// call the base function, important, odd behavior when connecting when not on same start scene
Expand Down Expand Up @@ -110,7 +108,10 @@ public override void OnStartServer()
// Use this for initialization
void Start()
{

// mirror does not garentee that start functions will be called in the same order on the server and client and when a client connects
// if (isServer) and if (isClient) are not sufficient controls
// move all start functions to OnStartClient() or OnStartServer(),
// be sure to call the base function or you will not get proper function when switching scenes and connecting
}

public override void OnStartClient()
Expand Down Expand Up @@ -210,6 +211,13 @@ void MySetActive(bool active, Quaternion rotation, bool playhyperspace)
}
}

[ClientRpc]
public void RpcStopMusic()
{
// stop the music at the end of the level
Camera.main.transform.gameObject.GetComponent<AudioSource>().Stop();
}

[ClientRpc]
public void RpcMySetActive(bool active, Quaternion rotation, bool playhyperspace)
{
Expand Down Expand Up @@ -262,6 +270,9 @@ void OnTriggerEnter(Collider other)
}

// we only shoot on the server
// clients control rockets but server controls shots,
// there is a bit of a delay difference and can result in client player rockets running into their own shots at high speed
// need to find a solution to this issue, moving the shot out further is not pretty
[Server]
void Fire()
{
Expand Down Expand Up @@ -454,6 +465,5 @@ void Update()
{

}

}
}
Binary file modified ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.

0 comments on commit 1fbedfd

Please sign in to comment.