Search Unity

Question How to Make a Round System of a Fighting Game Like Street Fighter or Mortal Kombat (C#)

Discussion in 'Scripting' started by TheFighterSFMK2022, Oct 12, 2022.

Thread Status:
Not open for further replies.
  1. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I have created a Street Fighter and I only did (Final Round) I wanted to do two rounds like Street Fighter or Mortal Kombat and I don't know how to do it or script, that's how I want it.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Usually a GameManager type of script would handle this, living through as many scenes as necessary until the game is won.

    There are tons of tutorials for the concept of a GameManager, and lots of different implementations.

    When you fully understand the basic concept of something called a GameManager that lives longer than a scene for this purpose, you are welcome to take a look at this code too:

    ULTRA-simple static solution to a GameManager:

    https://forum.unity.com/threads/i-need-to-save-the-score-when-the-scene-resets.1168766/#post-7488068

    https://gist.github.com/kurtdekker/50faa0d78cd978375b2fe465d55b282b

    OR for a more-complex "lives as a MonoBehaviour or ScriptableObject" solution...

    Simple Singleton (UnitySingleton):

    Some super-simple Singleton examples to take and modify:

    Simple Unity3D Singleton (no predefined data):

    https://gist.github.com/kurtdekker/775bb97614047072f7004d6fb9ccce30

    Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:

    https://gist.github.com/kurtdekker/2f07be6f6a844cf82110fc42a774a625

    These are pure-code solutions, DO NOT put anything into any scene, just access it via .Instance!

    If it is a GameManager, when the game is over, make a function in that singleton that Destroys itself so the next time you access it you get a fresh one, something like:

    Code (csharp):
    1. public void DestroyThyself()
    2. {
    3.    Destroy(gameObject);
    4.    Instance = null;    // because destroy doesn't happen until end of frame
    5. }
    There are also lots of Youtube tutorials on the concepts involved in making a suitable GameManager, which obviously depends a lot on what your game might need.

    OR just make a custom ScriptableObject that has the shared fields you want for the duration of many scenes, and drag references to that one ScriptableObject instance into everything that needs it. It scales up to a certain point.

    If you really insist on a barebones C# singleton, here's a highlander (there can only be one):

    https://gist.github.com/kurtdekker/b860fe6734583f8dc70eec475b1e7163

    And finally there's always just a simple "static locator" pattern you can use on MonoBehaviour-derived classes, just to give global access to them during their lifecycle.

    WARNING: this does NOT control their uniqueness.

    WARNING: this does NOT control their lifecycle.

    Code (csharp):
    1. public static MyClass Instance { get; private set; }
    2.  
    3. void OnEnable()
    4. {
    5.   Instance = this;
    6. }
    7. void OnDisable()
    8. {
    9.   Instance = null;     // keep everybody honest when we're not around
    10. }
     
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    Once you make a singleton (let's use Kurt's example above), here's the logic, exactly how it works in MK, but you can change it if you'd like.
    Code (csharp):
    1. public class RoundTracker : MonoBehaviour {
    2.  
    3.   private const int WINS_REQUIRED = 2;
    4.  
    5.   public enum Side {
    6.     Left = 0,
    7.     Right = 1
    8.   }
    9.  
    10.   static public RoundTracker Instance { get; private set; }
    11.  
    12.   int _leftWins, _rightWins;
    13.  
    14.   void Awake() => Reset();
    15.   void OnEnable() => Instance = this;
    16.   void OnDisable() => Instance = null;
    17.   void OnDestroy() => OnDisable();
    18.   public void Reset() { _leftWins = _rightWins = 0; }
    19.  
    20.   public void RecordRoundWinner(Side winner)
    21.     => setWins(winner, getWins(winner) + 1);
    22.  
    23.   public int CurrentWinsOf(Side side) => getWins(side);
    24.  
    25.   public int TotalRounds => _leftWins + _rightWins;
    26.  
    27.   public bool FinalRound()
    28.     => _leftWins == WINS_REQUIRED || _rightWins == WINS_REQUIRED;
    29.  
    30.   public Side FinalWinner => _leftWins > _rightWins? Side.Left : Side.Right;
    31.  
    32.   private int getWins(Side side)
    33.     => side == Side.Right? _rightWins : _leftWins;
    34.  
    35.   private void setWins(Side side, int value) {
    36.     if(side == Side.Right) _rightWins = value;
    37.       else _leftWins = value;
    38.   }
    39.  
    40. }
    Then someplace else you record the outcome of each round by doing
    Code (csharp):
    1. RoundTracker.Instance.RecordRoundWinner(winner: RoundTracker.Side.Left);
    Then you check for the overall winner before you proceed with the next round
    Code (csharp):
    1. var rt = RoundTracker.Instance;
    2. if(rt.FinalRound()) {
    3.   var winsTally = $"{CurrentWinsOf(RoundTracker.Side.Left)} to {CurrentWinsOf(RoundTracker.Side.Right)}";
    4.   Debug.Log($"After {rt.TotalRounds} rounds, the winner of the " +
    5.             $"match was the player on the {rt.FinalWinner:G}, " +
    6.             $"with the score of {winsTally}.");
    7. }
    Something like that.

    Edit:
    fixed a typo
    Edit2:
    added public to Reset, kind of important
     
    Last edited: Oct 13, 2022
  4. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    thanks for your help, orionsyndrome
     
  5. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    thanks to you too for your help, Kurt-Dekker
     
    Kurt-Dekker likes this.
  6. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
  7. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    And if you want intentionally to support a match draw (I think MK doesn't do that), then you'd have to change this to
    Code (csharp):
    1. // this can now return null as well, it's called a nullable value
    2. public Side? FinalWinner {
    3.   get {
    4.     if(_leftWins > _rightWins) return Side.Left;
    5.       else if(_rightWins > _leftWins) return Side.Right;
    6.     return null;
    7.   }
    8. }
    Then you gotta check for this special case afterward by doing this
    Code (csharp):
    1. var rt = RoundTracker.Instance;
    2. if(rt.FinalRound()) {
    3.   var winner = rt.FinalWinner;
    4.   var winsTally = $"{CurrentWinsOf(RoundTracker.Side.Left)} to {CurrentWinsOf(RoundTracker.Side.Right)}";
    5.   if(winner.HasValue) {
    6.     Debug.Log($"After {rt.TotalRounds} rounds, the winner of the " +
    7.               $"match was the player on the {winner.Value:G}, " +
    8.               $"with the score of {winsTally}.");
    9.   } else { // it's a draw
    10.     Debug.Log($"After {rt.TotalRounds} rounds, the match was a draw, " +
    11.               $"with the score of {winsTally}.");
    12.   }
    13. }
    Of course this assumes that you also modify FinalRound() to something specific, for example
    Code (csharp):
    1. public bool FinalRound() => TotalRounds == MAX_ROUNDS ||
    2.    Mathf.Abs(_leftWins - _rightWins) == WINS_REQUIRED;
    That makes sense, right?
    And then you add
    Code (csharp):
    1. private const int MAX_ROUNDS = 4; // as an example
    This would allow it to behave like a tennis match of sorts. Or a volley ball, or something like that, I don't follow any kind of sports any more.

    I'm seeing right now a couple more implications. You would have to think more thoroughly to come up with a fully-fledged logic, but this is all the code that you need. (Edit: I've modified this code slightly to make sure it works, see edit below for explanation.)

    If you need something specific, feel free to ask, I will modify this to accommodate for it.

    Edit:
    I've revisited this variant, it should work like this: the winner is whoever has the advantage of 2 wins, after round 4 the match is closed, and if the wins are equal then the match ends in a draw.
    Edit2:
    Final variant of this in Post #18
     
    Last edited: Oct 13, 2022
    TheFighterSFMK2022 likes this.
  8. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    CS0103 The name 'side' does not exist in the current context
     

    Attached Files:

  9. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    @TheFighterSFMK2022
    It's more helpful if you give me the exact line where this error shows up. You got the line number on the right, and in general, you just double click on that, and it'll show you. Anyway, I made a typo with this method
    Code (csharp):
    1. public void RecordRoundWinner(Side winner)
    2.     => setWins(winner, getWins(winner) + 1); // should be winner, not side
     
  10. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    didn't work,
    CS0111 The type 'RoundTracker' already defines a member named 'RecordRoundWinner' with the same types of.
     
  11. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    Oh, don't forget you can call
    Reset()
    to reset the whole thing! It also works in the inspector (in the top right corner).

    Although I forgot to make it public if you need to call it from code.
    Code (csharp):
    1. public void Reset() ... // just add public to the existing method
    And the call itself looks like this
    Code (csharp):
    1. RoundTracker.Instance.Reset();
    You need to replace the old one, can't keep both of them.
     
  12. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Your explanation is good, but I am having a series of many script problems.
     
  13. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    I'm glad mine is good, because your explanation is bad :D
    How am I supposed to fix it? If you don't tell me what's wrong I don't have time to run this in Unity atm, maybe tomorrow.
     
  14. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Code (CSharp):
    1. var rt = RoundTracker.Instance;
    2. if(rt.FinalRound()) {
    3.   var winner = rt.FinalWinner;
    4.   var winsTally = $"{CurrentWinsOf(RoundTracker.Side.Left)} to {CurrentWinsOf(RoundTracker.Side.Right)}";
    5.   if(winner.HasValue) {
    6.     Debug.Log($"After {rt.TotalRounds} rounds, the winner of the " +
    7.               $"match was the player on the {winner.Value:G}, " +
    8.               $"with the score of {winsTally}.");
    9.   } else { // it's a draw
    10.     Debug.Log($"After {rt.TotalRounds} rounds, the match was a draw, " +
    11.               $"with the score of {winsTally}.");
    12.   }
    13. }
    I don't know where to put it, because I get dizzy with those codes, I want to complete the script because I have errors that I can't solve, when I finish it I will understand the complete RoundTracker script.
     
  15. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    [código=CSharp]usando System.Collections;
    usando System.Collections.Generic;
    utilizando UnityEngine;

    clase pública RoundTracker: MonoBehaviour
    {

    privado const int WINS_REQUIRED = 2;
    privado const int MAX_ROUNDS = 4;
    Lado de enumeración pública
    {
    Izquierda = 0,
    Derecha = 1
    }

    Instancia de RoundTracker pública estática { get; conjunto privado; }

    int _leftWins, _rightWins;

    void Despertar() => Restablecer();
    void OnEnable() => Instancia = esto;
    void OnDisable() => Instancia = nulo;
    void OnDestroy() => OnDisable();
    void Restablecer () { _leftWins = _rightWins = 0; }

    public void RecordRoundWinner(Ganador del lado) => setWins(lado, getWins(lado) + 1);

    public int CurrentWinsOf(Side side) => getWins(side);

    public int TotalRounds => _leftWins + _rightWins;

    bool público FinalRound()
    => _leftWins == WINS_REQUIRED || _rightWins == GANANCIAS_REQUERIDAS;

    public Side FinalWinner() => _leftWins > _rightWins ? Lado.Izquierdo: Lado.Derecho;

    getWins privado int (lado lateral)
    => lado == Lado.Derecha ? _rightWins : _leftWins;

    setWins de vacío privado (Lado lateral, valor int)
    {
    if (lado == Lado.Derecho) _rightWins = valor;
    else _leftWins = valor;

    }


    Restablecer vacío público ()
    {
    RoundTracker.Instance.Reset();
    }

    Lado publico? Ganador final
    {
    obtener
    {
    if (_leftWins > _rightWins) devuelve Side.Left;
    de lo contrario, si (_rightWins > _leftWins) devuelve Side.Right;
    devolver nulo;
    }
    }
    public bool FinalRound() => TotalRounds == MAX_ROUNDS ||
    _leftWins >= WINS_REQUIRED || _rightWins >= WINS_REQUIRED;
    }[/código]
     
  16. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I don't know what's going on I can't upload the script (archive).
     
  17. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    it goes again
     

    Attached Files:

  18. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    You've done it again, you can't have the same method twice :) !
    If I said 'replace' that means delete the old one, i.e. copy/paste over it.

    Maybe it's a bad practice on my part, but with coding in general, you can't have duplicate items, unless you really want to access the same method in different ways, but in this case we don't want any duplicate items, mostly because I don't really want to complicate things.

    So if you added the last variant with 4 max rounds, and introduced the changed method FinalRound(), you absolutely have to replace the old one! It's on the line 32. This goes for FinalWinner property as well, it's already on line 35!

    Btw I have also updated this code (the 'max rounds' variant).

    So here it is again in its entirety, to try and calm the confusion down.

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class RoundTracker : MonoBehaviour {
    4.  
    5.   private const int MAX_ROUNDS = 4;
    6.   private const int ADVANTAGE_REQUIRED_TO_WIN = 2;
    7.  
    8.   public enum Side {
    9.     Left = 0,
    10.     Right = 1
    11.   }
    12.  
    13.   static public RoundTracker Instance { get; private set; }
    14.  
    15.   int _leftWins, _rightWins;
    16.  
    17.   void Awake() => Reset();
    18.   void OnEnable() => Instance = this;
    19.   void OnDisable() => Instance = null;
    20.   void OnDestroy() => OnDisable();
    21.   public void Reset() { _leftWins = _rightWins = 0; }
    22.  
    23.   public void RecordRoundWinner(Side winner)
    24.     => setWins(winner, getWins(winner) + 1);
    25.  
    26.   public int CurrentWinsOf(Side side) => getWins(side);
    27.  
    28.   public int TotalRounds => _leftWins + _rightWins;
    29.   public int CurrentAdvantage => Mathf.Abs(_leftWins - _rightWins);
    30.  
    31.   public bool FinalRound()
    32.     => TotalRounds == MAX_ROUNDS ||
    33.        CurrentAdvantage == ADVANTAGE_REQUIRED_TO_WIN;
    34.  
    35.   public Side? CurrentWinner {
    36.     get {
    37.       if(_leftWins > _rightWins) return Side.Left;
    38.         else if(_rightWins > _leftWins) return Side.Right;
    39.       return null;
    40.     }
    41.   }
    42.  
    43.   private int getWins(Side side)
    44.     => side == Side.Right? _rightWins : _leftWins;
    45.  
    46.   private void setWins(Side side, int value) {
    47.     if(side == Side.Right) _rightWins = value;
    48.       else _leftWins = value;
    49.   }
    50.  
    51. }
    Make sure you call the proper method in proper times.

    After the round is finished, don't forget to call RecordRoundWinner and assign the winner.
    Then, evaluate the match by checking first if FinalRound() is true (and everything else according to post #7).
    After the match is evaluated and the winner is determined (or it's a draw), don't forget to call Reset().

    The calls work like this, you can call from anywhere, assuming this script is alive and on some gameobject in the scene.
    Code (csharp):
    1. RoundTracker.Instance.FinalRound();
    You can also store this instance locally, so that you don't have to repeat yourself all the time.
    Code (csharp):
    1. void myFunction() {
    2.   var tracker = RoundTracker.Instance;
    3.   tracker.RecordRoundWinner(RoundTracker.Side.Right);
    4.   if(tracker.FinalRound()) {
    5.     // etc.
    6.   }
    7. }
    I've also added CurrentAdvantage property which you can evaluate on a round-to-round basis, if you want to.

    Finally, you can easily revert to classic MK behavior by setting MAX_ROUNDS to 3.
    This will prevent draws on its own and you won't have to change anything else.
     
    Last edited: Oct 13, 2022
  19. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I got the same error message again
    CS0103 The name 'side' does not exist in the current context
     
  20. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    If you're tracking your winners differently (for example 0 and 1) you can just do
    Code (csharp):
    1. int winnerIndex = 1;
    2. tracker.RecordRoundWinner((RoundTracker.Side)winnerIndex);
    Or if you really like to be verbose about this
    Code (csharp):
    1. int winnerIndex = 1; // or 0, it's probably some argument anyway
    2. switch(winnerIndex) {
    3.   case 1: tracker.RecordRoundWinner(RoundTracker.Side.Right); break;
    4.   default: tracker.RecordRoundWinner(RoundTracker.Side.Left); break;
    5. }
    That's because you gave me code with this error still in there.
    Now fix it on your own, hopefully you've learned what was wrong before.
     
  21. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I'll pass it to you
     

    Attached Files:

  22. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    Here

    But I must add, if you don't want to learn things as mundane as this, on your own, you're not going to make anything even remotely complex. The solution is there, and this is where I draw the line.
     
    angrypenguin likes this.
  23. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I put
    Code (CSharp):
    1. public Side side;
     
  24. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
  25. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    and I put it in GameObject and it only shows that there is only one public, do I have to put everything in public?
     
  26. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I'm going to put it in private or else I'll delete my "private Side side;" and that's how it's going to stay,
    i will try to understand.
     

    Attached Files:

  27. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Alr it's pretty obvious that your lost and don't even know whats going on, why do it then? You should start with something much similar, your wasting your time, others time and are gonna go home with nothing
     
  28. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I tried to solve and I still get an error,
    the only thing i did is that

    Code (CSharp):
    1. public void RecordRoundWinner(Side winner)
    2.       => setWins(Side.Left, getWins(Side.Right) + 1);
     
  29. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Thank you, the truth is that I try to make an effort to understand harder and I couldn't.
     
  30. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    I understand that you don't understand C# as clearly as I do, but can you at least comprehend that I actually placed a link for you to click?

    You know things become immensely hard if we can't even talk, let alone make computer programs. And yes it's a waste of everybody's time if you can't grasp something as simple as a link, which you're supposed to click, only to reveal a fix for a simple error that you've already encountered before and fixed it. It's literally above, in the same thread!

    This isn't C# any more, and if your brain is turned off, I'm not angry at you, but nobody can help you with that.
    So it's either time to go back a little, start learning baby steps, a lot of them, or I don't know, do something else.
     
    Kurt-Dekker likes this.
  31. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I know, and if what he says is right, I know he's not mad at me, (I already knew that) it's that he was thinking of sending the project (it's not a spoiler project, I just use the example of street fighter, just ryu and ken) It may be that you have errors in this project, or start a conversation to better synchronize, or try to read so that I understand the posts in this question, I'll come back in a few seconds, and I'll try to understand.
     
  32. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    Look, the fix for the error is there, in that post, I think we have some sort of language barrier.
    Here, let me show you

    This link
    https://forum.unity.com/threads/how...hter-or-mortal-kombat-c.1347818/#post-8509229

    leads you to what specifically has to be done to fix the last error you reported.

    You're supposed to rename that variable from 'side' -> 'winner' I told you back then it was a stupid typographic error, and it's so crazy obvious, AND ALREADY FIXED, that it's literally mind boggling that you're trying to code in C# without being equipped with such basic understanding already.

    You can also go back a little (to post #18) and copy/paste the whole thing again, because I've already fixed it there.

    But I'm not helping you any more. Because I'm not helping at all, and you're depleting me.
    I'm sorry.

    You're likely very young and are still learning the basics, but you have to try harder, and we'll see you again.
    We simply can't talk if you cannot speak. We cannot run a marathon if you can't walk, that sort of thing.
    In the meantime, hopefully the solution will serve as a good example for you and other people coming into game dev.

    Good luck.
     
    Nad_B and TheFighterSFMK2022 like this.
  33. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Is right, thanks for everything, orionsyndrome, sorry to wear you out, yes, I will see it again until tomorrow.
     
  34. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Its nothing about trying to understanding 'harder' because if you don't know it, you dont know it. And theres nothing bad about that, Im not mad or anything, but trying to understand the language instead asking how to do something you don't know what it is. Start with simple basics, you'll see how c# works, theres a hella lot of tutorials to help you learn. It takes time, you can't start learning a language in minutes, took me 1 year to learn simple greetings in french. Its gonna take time and thats something you gotta commit, and the longer you work harder in learning instead of depending on people, the more quicker you'll understand and problems like these would be solved in minutes. We don't need 33 replies for some sloppy hand errors now do we
     
    TheFighterSFMK2022 likes this.
  35. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    Don't get me wrong, you aren't really wearing me out, I have plenty of energy -- though I am somewhat impatient, that's part of my personality I guess -- you're literally depleting my time, because I do this as a distraction of sorts, in very little spare time I have.

    I try to be idiotically efficient with a) first of all, honing my own mental skills, i.e. out of box thinking, metathinking and problem-solving, and then after I'd stoically accomplish that b) I've also taught someone, helped this world a little, left some mark, that sort of thing.

    And by doing all of this, I'm also socially engaged and locked in a thought process which is atypical for my everyday environment, an environment that's literally devastating for any creative mind set, and I'm going a little crazy because of this incredibly unjust isolation I've found myself in, which is my prime motivation to be here, in fact.

    I also practice being embedded in a different culture, which is already the culture that's supposed to be a user of my soon-to-be products, and so I really need a gateway to, sort of, soak in as much information as I can, and I truly believe this is the ultimate win in every aspect.

    So no, I don't mind or hate that you're a newbie, and you're not wearing me, it's just, well I hate myself for stretching out too far and too thin. I have a radically more complex project in my hands, and I have to think of some really crazy abstract machines to work this all out, and I'm also having a ridiculously hard time financially and existentially, so this is supposed to be my weird way to cool off, like doing crossword puzzles, and I really don't mean to offend anyone.

    So when I'm critical, I'm probably critical of myself first and foremost. I hate that I can't just plop a solution and go chase my own dragons. I have to explain every little screw, because without a context nothing has a meaning. I probably just wish someone would've handed all of this to me when I was your age, but the world consists of opposites, I see, and I'm probably not quite ready for it yet.

    Therefore I have to back off to conserve my worldview. And by extension, my sanity. If I can't help you, this distraction I've set myself up with, is simply a nonsense and I am truly wasting my time on this planet. There are much more pressing issues that I have to attend. And so, in this spiral, I lose all enthusiasm to help anyone, which is outright wrong, but rational. I don't like the world we live in, and I think being rational isn't actually a good metric for having a meaningful life.

    So you're not wearing me out, you're pushing me to pick between either wasting my time or leading a life without meaning. I somehow can't opt out.
     
    Last edited: Oct 13, 2022
    TheFighterSFMK2022 likes this.
  36. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I wanted to give you the easy option, but I think it won't work, I'm going to send you the project (it's not the project of my game that I'm working on, but it's another test project of a fighting game it's a test game of street fighter ryu and ken), I have the theory that my project could be due to other scripts that give errors, I think not, it was me, and second, it may be that it is going to tell me that it cannot upload from other projects and everything else, and thirdly, having to see more errors in the scripts but no, it only appears two, but I understood a little, I have to sleep, it is 02:09 am, in Argentina that is the time, and tomorrow I will understand it all.
     
    Johan_Liebert123 likes this.
  37. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Alright lets start fresh tomorrow, I would like you to send your current script what you have, and the error you are receiving (if any) or an explanation of what is happening and whats not working
     
  38. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I'm back, I've been watching other videos on the internet, and I understood it a little, but I haven't been able to understand this RoundTracker script because I have to add it in Awake and I couldn't or it wasn't in awake or I don't know, that's how my project is try it, not the other one that has a spoiler,

    because he uploaded this video is because to find out which characters I have to put the one with the script or I don't know, if I don't understand what this video says I can pass the test project if I do you want it or not, if you want it to solve my project you have to upload a video (not public) so I could fully understand it or post a photo if you don't want to upload a video, that's all, and then I'll do it alone but I'll still keep sending you I need help, first I'm going to do round 2 (round 3 not final round)
     
  39. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    By the way, I use the google translator, if I translate it wrong or put it in Spanish (it may be in that video), you can use the google translator if you don't know in Spanish,
     
  40. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    yes, I do not force you to upload a video so that I can solve this script, if you do not want
     
  41. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Your problem has already been explained before by @orionsyndrome above,
    ^^ This post here, it tells you everything you need to know, he gives the full script, how to use it etc. I'm not sure how to link you to that exact post but scroll up a bit and you'll see it
     
  42. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    if I update the script, but I don't know how I will know if it worked

    Code (CSharp):
    1. public enum Side
    2.     {
    3.         Left = 0,
    4.         Right = 1
    5.     }
    I don't know where I have to put ryu 0 and ken 1
     
  43. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    ryu and ken have the same script, the script is called Fighter
     
  44. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,998
    If you want to try it from scratch, or think of what everyone else wrote in terms of "what does this part do?" better, here's a way to think of it:

    Let's call everything you wrote so far "DoOneFight". Step 1 of making it do Best of 3 is being able to do it over and over. That's tricky, since you have to reset health meters, player positions, maybe clear off the blood from the mat... . But Unity makes this simple with Scenes. You probably have your DoOneFight in 1 scene (Unity forces you to make at least one). All you have to do is figure out how to get Unity to unload a scene (which deletes everything it it) and restart it (which resets everything). Have the end of the fight do that. At this point you should have the fight going over and over.

    Step2 is tricky -- we need to _remember_ stuff between fights. For now, let's just remember the round. Each time the fight starts it can say "Round X", where X actually goes up. A simple way to do that is to make a starting scene with a "The Whole Game" script. If will have the round counter. That scene will need a way to start your DoOneFight scene without deleting your "The Whole Game" script. Unity likes to completely delete an old scene when you load new one, but there are tricks to get around it (made exactly for this purpose).

    Step2B is changing the end of your fight so it doesn't just rerun itself. We need it to somehow return to the The Whole Game script, so it can increase the counter. There are a few ways. You could have it find your "The Whole Game" script and say "I'm done". Or the "The Whole Game" script could constantly check "is the fight over?". However you do it, a "Fight Ended" part of of your Whole Game Script will add 1 to the rounds, and restart DoOneFight. Now you have infinite fights, with a visible round counter. To test, temporarily give everyone 1 health, or make it so pressing "v" does 10,000 damage to one player.

    Step3 is simple once you have step 2. Add a win counter to the Whole Game script. Just before restarting the fight, have it check for 2 wins from either player. If that happens, have it bring up the Victory screen instead of restarting the fight. An easy way to do that is to make the Victory scene in the same intro script, but hidden (Unity makes this easy). On a victory, unhide it.
     
    TheFighterSFMK2022 likes this.
  45. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    What part do I put (restart) so that the fight comes back again and again, or how is the script to download the scene, for the introduction.
     
  46. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,998
    This is just one small step, where all we have is your current game. Clearly, you want to restart in the part where your game sees that it's over. Somewhere you have something that says "Player X wins", right? A restart would go there. Since it's so simple, you can google "Unity restart scene". You probably want a small delay before restarting, but that also seems like a common thing "Unity delay" should find a way.

    But that's if you want to mess around and learn how everything works, so that the final script is something you understand and know how to change later. You could also just look at the scripts people up above wrote, thinking things like "OK, part of this restarts the fight -- where is it?" "Part of this creates a TheWholeGame master script -- where is that?" and so on.
     
    TheFighterSFMK2022 likes this.
  47. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    can it be this?
     
  48. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I was able to get the game to restart (later I am going to fix the unity delay until I get the round system like street fighter or mortal kombat), I forgot to tell you that I had already done the unity restart before, how have I got other new things now I'm going to go to next step 2, (I prefer to record but well, don't do anything else you want.)
     
  49. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I was uploading my project on github just in case, it won't even let me, tomorrow it will, and i will keep fighting the roundtraker script to try to understand, I'm going to sleep.
     
  50. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144

    I already did the reset for the scene, for now I leave it like this,
    I'm leaving step 2, and now what do I have to do?
     
Thread Status:
Not open for further replies.