Pages 1
Universal Fighting Engine Forum Due to increased bot activity, we have discontinued support through the forum. For assistance, questions, and community discussions, please join our official Discord server |
You are not logged in. Please login or register.
Universal Fighting Engine Forum → Source Coding → Who Pressed The Pause Button
Conceptually speaking. The DefaultBattleGUI shows in the DoFixedUpdate() method
if(
// Check if both players have their life points above zero...
UFE.GetPlayer1ControlsScript().currentLifePoints > 0 &&
UFE.GetPlayer2ControlsScript().currentLifePoints > 0 &&
UFE.gameMode != GameMode.NetworkGame &&
(
// and at least one of the players have pressed the Start button...
player1CurrentStartButton && !player1PreviousStartButton ||
player2CurrentStartButton && !player2PreviousStartButton
)
){
// In that case, we can process pause menu events
UFE.PauseGame(!UFE.isPaused());
}
So I imagine if you split up that if statement you can set a global variable that states which player paused the game.
For example:
if(
// Check if both players have their life points above zero...
UFE.GetPlayer1ControlsScript().currentLifePoints > 0 &&
UFE.GetPlayer2ControlsScript().currentLifePoints > 0 &&
UFE.gameMode != GameMode.NetworkGame
){
// In that case, we can process pause menu events
if (player1CurrentStartButton && !player1PreviousStartButton) {
player1Paused = true;
UFE.PauseGame(!UFE.isPaused());
} else if (player2CurrentStartButton && !player2PreviousStartButton) {
player2Paused = true;
UFE.PauseGame(!UFE.isPaused());
}
}
@MrPonton: Thank you very much for your help!
I made some modifications and it's free for anyone to use for their projects.
1) I create a script for global variables and I added these lines:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Global : MonoBehaviour
{
public static bool player1Paused;
public static bool player2Paused;
public static string characterName;
}
2) I made changes in the DefaultBattleGUI.cs with this code:
if(
// Check if both players have their life points above zero...
UFE.GetPlayer1ControlsScript().currentLifePoints > 0 &&
UFE.GetPlayer2ControlsScript().currentLifePoints > 0 &&
UFE.gameMode != GameMode.NetworkGame
){
// In that case, we can process pause menu events
if (player1CurrentStartButton && !player1PreviousStartButton) {
Global.player1Paused = true;
Debug.Log("Player 1: " + this.player1GUI.name.text + " pressed the pause button");
Global.characterName = this.player1GUI.name.text;
UFE.PauseGame(!UFE.isPaused());
} else if (player2CurrentStartButton && !player2PreviousStartButton) {
Global.player2Paused = true;
Debug.Log("Player 2: " + this.player2GUI.name.text + " pressed the pause button");
Global.characterName = this.player2GUI.name.text;
UFE.PauseGame(!UFE.isPaused());
}
}
3) I created a script called SpecialMoves.cs and added it into the Special Moves object in the Pause Prefab:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SpecialMoves : MonoBehaviour
{
public Text mytext = null;
// Start is called before the first frame update
void Start()
{
StartCoroutine(SpecialMovesText());
}
IEnumerator SpecialMovesText() {
if (Global.player1Paused == true)
{
if (Global.characterName == "Billy")
{
mytext.text = "Billy's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
if (Global.characterName == "Jane")
{
mytext.text = "Jane's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
}
if (Global.player2Paused == true)
{
if (Global.characterName == "Billy")
{
mytext.text = "Billy's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
if (Global.characterName == "Jane")
{
mytext.text = "Jane's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
}
}
}
Cool. Some advisements I'd recommend on this section:
if (Global.player1Paused == true)
{
if (Global.characterName == "Billy")
{
mytext.text = "Billy's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
if (Global.characterName == "Jane")
{
mytext.text = "Jane's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
}
if (Global.player2Paused == true)
{
if (Global.characterName == "Billy")
{
mytext.text = "Billy's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
if (Global.characterName == "Jane")
{
mytext.text = "Jane's Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
}
You don't have to say '== true' as an if statement is a boolean check anyways.
You could add to your Global an enum of all the characters so you can avoid having to make more edits, or you could just run through the entire UFE character list in a LINQ statement to figure out which character was selected. It depends on how you handle your objects and code in the rendering of the character's special moves you want to show.
Caution though with the enum path, it would probably only work if your characters were single names as the .ToString() method of an enum member will just convert the enum value as written. So if you have "Global.Characters.JohnDoe" then the string will appear as "JohnDoe" instead of "John Doe". There's a trick you can do to override that but requires also a custom method which if you need that help let me know.
Additionally, the double if is unnecessary as you're creating branch checks. For example, if the character is Billy, then even though we know it's Billy and have done the code inside that if check, right after you're asking the cpu to check if the character is now Jane, and after checking if it's both Billy or Jane, you're checking if player 2 also paused. While small instances of this are negligible performance issues, you'll run the risk of it getting worse as you add more character checks, even if you do properly set it to an if/else if/else. You'd most likely want a switch statement honestly. And again depending on how you are displaying the special moves list might alter how much you can refactor an simplify your code there.
Also, there's no difference in your code on the SpecialMovesText() IEnumerator between player 1 and player 2 honestly pressing pause, as it's assuming that's been handled in the DefaultBattleGUI().
Lastly, You should do somewhere in your code, most likely when you dismiss the pause screen, to set the Global.player1Paused and Global.player2Paused back to false as since they are static it will never be rest unless you manually reset them. Could probably even make a custom method to do it such as Global.PlayersUnpaused() that just sets each to false when pause menu has been dismissed.
So you could simplify it to this:
if (Global.player1Paused || Global.player2Paused)
{
mytext.text = $"{Global.characterName}'s Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
That of course is doing the same thing as the original block of code without all the ifs and would just be printing the character's name, but if you would want to do something specific and different depending on the character you'd do:
if (Global.player1Paused || Global.player2Paused)
{
switch (Global.characterName)
{
case "Billy":
RenderBillysSpecialMoveList();
break;
case "Jane":
RenderJanesSpecialMoveList();
break;
default:
mytext.text = $"{Global.characterName}'s Special Moves List";
yield return new WaitForSecondsRealtime(999999);
}
}
@MrPonton Works perfectly! This could help we with other scripts in my project. I didn't even need the Coroutine. Thank you
I think this thread is solved now, there's was this also tough
http://www.ufe3d.com/forum/viewtopic.php?id=1030
Universal Fighting Engine Forum → Source Coding → Who Pressed The Pause Button
Powered by PunBB, supported by Informer Technologies, Inc.