Skip to content

Commit

Permalink
Game resets after Lose_music has finished playing
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble committed Feb 21, 2018
1 parent 292758c commit 8becf41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
47 changes: 18 additions & 29 deletions Assets/Scripts/GameManager_level01.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class GameManager_level01 : MonoBehaviour, IGameManager
public GameHealthManager gameHealthManager;
public GameUI_ImportantMessage importantMessage;

private float timeToStart = 3f;
public string sceneLoadedOnRestart = "menu";

public bool started = false;
public bool levelEnded = false;

Expand Down Expand Up @@ -56,13 +57,6 @@ void Update()
GameStart();
if (Input.GetKeyUp(KeyCode.S))
GameLost();
if (timeToStart >= 0)
{
//timeToStart -= Time.deltaTime;
} else
{
//GameStart ();
}
}
if (started)
{
Expand All @@ -88,18 +82,6 @@ void Update()
}
}

public void GameLost()
{
levelEnded = true;
print("You have lost the game");
spawnManager.StopSpawning();
importantMessage.Show("Game Over");
SoundManager.PlayLevelLostSound();
//Invoke ("LoadMenu", 5f);
//change scene??
Invoke("GameRestart", 10f);
}

public void GameStart()
{
if (started)
Expand All @@ -120,22 +102,29 @@ public void GamePause()
throw new System.NotImplementedException();
}

public void GameRestart()
{
SceneManager.LoadScene("menu");
}

public void GameWin()
{
levelEnded = true;
print("You have won the game");
importantMessage.Show("Game Win");
SoundManager.PlayWinFanfare();
Invoke("GameRestart", 5f);

AudioClip sound = SoundManager.PlayWinFanfare();
Invoke("GameRestart", Mathf.Max(sound.length, 5f));
}

void LoadMenu()
public void GameLost()
{
levelEnded = true;
print("You have lost the game");
spawnManager.StopSpawning();
importantMessage.Show("Game Over");

AudioClip sound = SoundManager.PlayLevelLostSound();
Invoke("GameRestart", Mathf.Max(sound.length, 10f));
}

public void GameRestart()
{
SceneManager.LoadScene("menu");
SceneManager.LoadScene(sceneLoadedOnRestart);
}
}
2 changes: 1 addition & 1 deletion Assets/Scripts/ResetHotkeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ResetHotkeys : MonoBehaviour
{
public string sceneLoadedWhenReset;
public string sceneLoadedWhenReset = "menu";

private SteamVR_Controller.Device[] controllers = null;

Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Sound/SoundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ public static void PlayCrowSound(Vector3 point)
Destroy(audio.gameObject, THIS.crowSound.length);
}

public static void PlayLevelLostSound()
public static AudioClip PlayLevelLostSound()
{
THIS.levelMusicChild.GetComponent<AudioSource>().Stop();
THIS.audioSource.PlayOneShot(THIS.gameLost);
return THIS.gameLost;
}

public static void PlayWinFanfare()
public static AudioClip PlayWinFanfare()
{
THIS.levelMusicChild.GetComponent<AudioSource>().Stop();
THIS.audioSource.PlayOneShot(THIS.gameWon);
return THIS.gameLost;
}

public static void PlaySoundAtPoint(AudioClip sound, Vector3 point, float volume = 1f, Transform parent = null)
Expand Down

0 comments on commit 8becf41

Please sign in to comment.