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
    Last edited: Oct 28, 2022
  2. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    By the way, the animation is outside of assets, you can delete that it is outside of assets, it is also the first time it was uploaded to github, and I could not delete it.
     
  3. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    @orionsyndrome @Johan_Liebert123 @Owen-Reynolds just to be clear that, I'm not using anyone (I hate doing that kind of thing), I'm just asking you to help me so that you can guide me the way, so that I can work on my fight project, I I give my project as a test, and I can't pass the other one because I'm going to give him a spoiler that I'm working on or if he steals my idea of my project, if you'll excuse me I'll choose whether to laugh or continue with my test project, to discover that script (RoundTracker), I tell you this message just in case.
     
  4. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    and I also get frustrated when I solve the RoundTracker script.
     
  5. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I already updated the RoundTracker script and I'm starting to give up, I don't know what else to do.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    You must find a way to get the information you need in order to reason about what the problem is.

    Once you understand what the problem is, you may begin to reason about a solution to the problem.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling
    Debug.Log()
    statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as
    Debug.Log("Problem!",this);


    If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

    You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

    You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ or this answer for Android: https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

    When in doubt, print it out!(tm)

    Note: the
    print()
    function is an alias for Debug.Log() provided by the MonoBehaviour class.
     
  7. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    thanks, I'll try it, but I'll still be waiting for the hope that I downloaded the test project or tell me where I put Debug.Log() the script of RoundTracker
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class RoundTracker : MonoBehaviour
    4. {
    5.  
    6.     private const int MAX_ROUNDS = 4;
    7.     private const int ADVANTAGE_REQUIRED_TO_WIN = 2;
    8.  
    9.     public enum Side
    10.     {
    11.         Left = 0,
    12.         Right = 1
    13.     }
    14.  
    15.     static public RoundTracker Instance { get; private set; }
    16.  
    17.     int _leftWins, _rightWins;
    18.  
    19.     void Awake() => Reset();
    20.     void OnEnable() => Instance = this;
    21.     void OnDisable() => Instance = null;
    22.     void OnDestroy() => OnDisable();
    23.     public void Reset() { _leftWins = _rightWins = 0; }
    24.  
    25.     public void RecordRoundWinner(Side winner)
    26.       => setWins(winner, getWins(winner) + 1);
    27.  
    28.     public int CurrentWinsOf(Side side) => getWins(side);
    29.  
    30.     public int TotalRounds => _leftWins + _rightWins;
    31.     public int CurrentAdvantage => Mathf.Abs(_leftWins - _rightWins);
    32.  
    33.     public bool FinalRound()
    34.       => TotalRounds == MAX_ROUNDS ||
    35.          CurrentAdvantage == ADVANTAGE_REQUIRED_TO_WIN;
    36.  
    37.     public Side? CurrentWinner
    38.     {
    39.         get
    40.         {
    41.             if (_leftWins > _rightWins) return Side.Left;
    42.             else if (_rightWins > _leftWins) return Side.Right;
    43.             return null;
    44.         }
    45.     }
    46.  
    47.     private int getWins(Side side)
    48.       => side == Side.Right ? _rightWins : _leftWins;
    49.  
    50.     private void setWins(Side side, int value)
    51.     {
    52.         if (side == Side.Right) _rightWins = value;
    53.         else _leftWins = value;
    54.     }
    55.     void myFunction()
    56.     {
    57.         var tracker = RoundTracker.Instance;
    58.         tracker.RecordRoundWinner(RoundTracker.Side.Right);
    59.         if (tracker.FinalRound())
    60.         {
    61.             RoundTracker.Instance.FinalRound(); // etc.
    62.         }
    63.     }
    64. }
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    It will be necessary for you to understand your program in order to fix or extend it.

    This line and several of your previous posts:

    ... makes me suspect you have not taken the time to understand the program you are working with.

    Go back to square one and work through all the steps about how this program works.

    It is not optional.

    Pay extremely close attention to Step #2 below;

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!

    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.


    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
  9. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Thanks I'll try
     
  10. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    @TheFighterSFMK2022
    Have you ever watched Dr. House? You know how every single patient he ever treats always lies somehow? It's always a little exaggerated of course, but it has to do with shame, with ridicule, with false ego or pride, yet they all come to see a medical doctor, and these things matter to them more than their health. Dr. House is this hyper-rational character who always muses sarcastically with the rest of the humanity, even though he's as much as flawed as anyone, and this would make him brutally cynical if he wasn't already very likable and perhaps too honest.

    So pardon me if I'm like Dr. House (again), but
    your lies begin and end here.

    Had you been honest about this, how you knew next to nothing, and that this was a homework assignment, you'd be approached completely differently. But you're like "I made this" and then "2+2 is how much?" and then "what's 2?" and then "crap this doesn't work, nobody wants to help me".

    Of course nobody wants to help you, because you actually don't want to learn any of this, you're just pretending. All of these things that we showed you are knowable by definition and most of them (if not all) are extremely easy to learn and find anywhere, on Youtube, in articles, in schools, in books... It's the end of 2022. You don't even know what debugging means or what's the purpose of it. In your defense, I just hope you're really young, like 10, 12, 14 tops, because if you're older, you're wasting a slot in that school. C'mon show some genuine effort. Who doesn't like making games?

    In my case, nobody ever actively taught me how to do any of this. I never paid for any of this knowledge (other than the hardware and the internet I'm using, and that hardware is not really that impressive), and I never went to any school except the ones mandated by the government. And what you're doing here is the literal opposite of what I had to go through. Zero excuses. I had to fight and prove myself, and some residues of that mentality still linger on.

    So no, you're not using anyone, this forum tracks information that will be of use to many people coming here via Google or through forum search. If they are interested in what you're doing and what solutions you got, it's all public.

    I'm always gonna help as much as I can, but I can't work for you, and I can't possibly learn in your place.
     
    Kurt-Dekker, Yoreki and Nad_B like this.
  11. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    No, I only know MilHouse (the Simpson), now! Now let's get serious.


    this is serious, what happens is that I don't know what I can try to do a test to do the script round, and I tried everything and I couldn't and I looked at your first posts what happens is that there is no video where you will put the ryu characters is left ken is right, where do I put that, where can I do the test and I'm not lying to anyone, I don't know if you saw my video of my test project that I show you my project, that I did everything possible and nothing, and now I'm watching a video from the internet that Spanish:

    if you want in English it's this, I don't know if I had a video about SINGLETON in English,

    I clarify this, if I was lying I would not be making the publication here.
     
    Last edited: Oct 16, 2022
  12. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    I have literally quoted what you said.

    And I don't care about that actually, just like Dr. House doesn't.
    It's your life, I'm just stating why you're having difficulties understanding any of this, and why we can't help you.

    You're stuck with the most basic of the things, people tell you you're lost, that's how removed you are, yet whoever approaches you with a wholesome advice, like Kurt, you just say "I'll try" and do nothing. You have no legit questions, and you constantly demonstrate that you want us to implement the whole thing. Please stop.

    As much as I would like to
    1) I really really don't have time at the moment, I'm basically gone for a couple of days starting from today
    2) I have ethical issues with it, if this would make you a "better student" -- to hell with it, I don't want you to sit in some government or company tomorrow, making decisions the same way you're "learning" right now

    And I can't really tell if there is a massive issue with your translation and all meaning is lost, but stop saying "I'll try" and actually TRY. Make something on your own. Heck you could've made anything with that code I gave you, you could've simulated winning by pressing 1 and 2 on your keyboard, then try figuring out how to make this happen in a real fight.
     
    Yoreki likes this.
  13. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    He told me that I can search the internet and YouTube SINGLETON and I did.
     
  14. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    one question, can you put image in your script when win left?
     
  15. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Just use mono behaviours don’t over complicate things. As a new programmer stick with mono-behaviour.
    You need a Game script. The Game script has reference to both fighter objects. And their health.
    When you damage an object you talk to game script for the object that is not your fighter, and reduce their associated health int or float.

    People on the forum love a good pointless argument. And not all advice is good. Kurts advice is pretty good. But sometimes people want to reduce others intelligence under the selfish vice that they have a wife and kid to pay for. But you understand not alot of people will get involved helping write tutorials for the specific questions or to provide free teachings. .

    However,


    The way i did was only mono behaviour

    a game script asked for object 1 and 2, had an int for obj 1 and 2. It doesn’t matter what side of the screen the objects are on that is a UI design choice, just matters that the two fighters have a health pool associated with their object order.

    you can do everything from monobehaviour required for a fighting game. Since nothing is really happening except your fighters. There is no need to do all this other stuff especially not at your level of programming experience.

    there is no harm starting a new project and playing around with a cube on screen moving it around within bounds before turning it into a fighting game. This way you can get all info needed to understand exactly where the game is at, where you are at; and take on the problems one step at a time. Otherwise it become confusing and as you can tell frustrating.

    Just keep things stupid simple. And do stupid simple from the get go.
     
    TheFighterSFMK2022 likes this.
  16. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Thanks, AnimalMan.
     
    AnimalMan likes this.
  17. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I will continue until tomorrow, the time here in argentina is 04:08 am, it's too late for me.
     
    AnimalMan likes this.
  18. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    I consider moving to Argentina
    Sleep well, take it easy.
     
    TheFighterSFMK2022 likes this.
  19. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Ayy man no need for that, however he said it, whatever he said was true, mans saying he doesn't know where to put Debug.Log and is saying I created that whole game, I watched the video, no way he created that and doesnt know what Debug.Log is, and I don't think he's here for a pointless argument as orionsyndrome actually spent soo much time helping him out, check the last page, I couldnt/wouldn't spend soo much time with all those posts for someone not even knowing what they want
    Your fooling your self if you really think he's here to steal 'your' game which 'you' made, im being honest right now, stop what your doing, you've got no idea whats going on in your project, create a new project and actually start learning how to use unity and c#, your wasting your own time and everyones time here

    You don't know whats going on in RoundTracker.cs, here I'll explain it.
    Code (CSharp):
    1. private const int WINS_REQUIRED = 2;
    This is for the number of wins required for either ryu or ken
    Code (CSharp):
    1.     public enum Side
    2.     {
    3.         Left = 0,
    4.         Right = 1
    5.     }
    You need to determine who's who, so lets say left is ryu and ken's on the right, this will help keeping track of player wins etc.

    Code (CSharp):
    1.     public void Reset()
    2.     {
    3.         _leftWins = _rightWins = 0;
    4.     }
    Calling reset, resets the player wins, this is why it's called in the Awake function so it's set to 0 each new game

    Code (CSharp):
    1. public void RecordRoundWinner(Side winner)
    2. {
    3.       setWins(winner, getWins(winner) + 1);
    4. }
    Now, what does this do? So we've declared the side as winner, so at the end of the round you call this for either side 1 or 2 (ryu or ken). You will call this when someone's health is at 0
    Orinsyndrome has used2 methods here, setWins and getWins.
    Code (CSharp):
    1.     private int getWins(Side side)
    2.       => side == Side.Right ? _rightWins : _leftWins;
    3.  
    4.     private void setWins(Side side, int value)
    5.     {
    6.         if (side == Side.Right) _rightWins = value;
    7.         else _leftWins = value;
    8.     }
    getWins basically graps an int, of the number of wins for each player, that basically means if it's the right player, get the right players wins, else get the left players wins
    setWins is a method, side and a vale being declared, when you use this, you'll need the player to set the win for, and a value. And the same thing is happening here, he's checking who is the player, then settings his wins, both these methods are used in RecordRoundWinner.
    Code (CSharp):
    1.  public int TotalRounds => _leftWins + _rightWins;
    This just checks for Total Rounds, use this when you wanna check for rounds or whatever, pretty self explanatory
    Code (CSharp):
    1. public Side FinalWinner => _leftWins > _rightWins ? Side.Left : Side.Right;
    This checks for the winner, it's basically saying if leftWins are greater then rightWins, left side is the winner, else the right side is.

    Easy, right. You want to call these in your GameManager script whenever necessary.
    Now, is there anything you do not understand what is going on?

    PS: If i'm wrong please correct me where
     
    TheFighterSFMK2022 and AnimalMan like this.
  20. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    You’re right I’m stay out of it
     
    TheFighterSFMK2022 likes this.
  21. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I hope that you know also in Spanish, because sometimes I make mistakes in the translation.
     
  22. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144

    can i put this to fighter script?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class Fighter : MonoBehaviour
    5. {
    6.     public enum PlayerType
    7.     {
    8.         HUMAN, AI
    9.     };
    10.  
    11.     public enum Side
    12.     {
    13.         Left = 0,
    14.         Right = 1
    15.     }
    16.  
    17.     public static float MAX_HEALTH = 100f;
    18.    
    19.     public float healt = MAX_HEALTH;
    20.     public string fighterName;
    21.     public Fighter oponent;
    22.     public bool enable;
    23.     public float velocidad = 0.0f;
    24.     public float aceleracion = 0.1f;
    25.     public float desaceleracion = 0.5f;
    26.     public PlayerType player;
    27.     public Side playerRL;
    28.     public FighterStates currentState = FighterStates.IDLE;
    29.  
    30.     protected Animator animator;
    31.     private Rigidbody myBody;
    32.     private AudioSource audioPlayer;
    33.  
    34.     //for AI only
    35.     private float random;
    36.     private float randomSetTime;
    37.  
    38.    
    39.  
    40.     // Use this for initialization
    41.     void Start()
    42.     {
    43.         myBody = GetComponent<Rigidbody>();
    44.         animator = GetComponent<Animator>();
    45.         audioPlayer = GetComponent<AudioSource>();
    46.     }
    47.  
    48.     public void UpdateHumanInput()
    49.     {
    50.         bool moverseoprimido = Input.GetKey(KeyCode.RightArrow);
    51.        
    52.        
    53.  
    54.         if (moverseoprimido && velocidad < 1.0f)
    55.         {
    56.             velocidad += Time.deltaTime * aceleracion;
    57.         }
    58.         if (!moverseoprimido && velocidad > 0.0f)
    59.         {
    60.             velocidad -= Time.deltaTime * desaceleracion;
    61.         }
    62.         if (!moverseoprimido && velocidad < 0.0f)
    63.         {
    64.             velocidad = 0.0f;
    65.         }
    66.         if (Input.GetAxis("Horizontal") < -0.1)
    67.         {
    68.             if (oponent.attacking)
    69.             {
    70.                 animator.SetBool("WALK_BACK", false);
    71.                 animator.SetBool("DEFEND", true);
    72.             }
    73.             else
    74.             {
    75.                 animator.SetBool("WALK_BACK", true);
    76.                 animator.SetBool("DEFEND", false);
    77.             }
    78.         }
    79.         else
    80.         {
    81.             animator.SetBool("WALK_BACK", false);
    82.             animator.SetBool("DEFEND", false);
    83.         }
    84.  
    85.         if (Input.GetAxis("Vertical") < -0.1)
    86.         {
    87.             animator.SetBool("DUCK", true);
    88.         }
    89.         else
    90.         {
    91.             animator.SetBool("DUCK", false);
    92.         }
    93.  
    94.         if (Input.GetKeyDown(KeyCode.UpArrow))
    95.         {
    96.             animator.SetTrigger("JUMP");
    97.         }
    98.  
    99.         if (Input.GetKeyDown(KeyCode.Space))
    100.         {
    101.                 animator.SetTrigger("PUNCH_R");
    102.         }
    103.  
    104.         if (Input.GetKeyDown(KeyCode.K))
    105.         {
    106.             animator.SetTrigger("KICK_R");
    107.         }
    108.  
    109.         if (Input.GetKeyDown(KeyCode.H))
    110.         {
    111.             animator.SetTrigger("HADOKEN");
    112.         }
    113.  
    114.    
    115.         animator.SetFloat("Camina", velocidad);
    116.     }
    117.  
    118.    
    119.  
    120.     public void UpdateAiInput()
    121.     {
    122.         animator.SetBool("defending", defending);
    123.         //animator.SetBool ("invulnerable", invulnerable);
    124.         //animator.SetBool ("enable", enable);
    125.  
    126.         animator.SetBool("oponent_attacking", oponent.attacking);
    127.         animator.SetFloat("distanceToOponent", getDistanceToOponennt());
    128.  
    129.         if (Time.time - randomSetTime > 1)
    130.         {
    131.             random = Random.value;
    132.             randomSetTime = Time.time;
    133.         }
    134.         animator.SetFloat("random", random);
    135.     }
    136.  
    137.     // Update is called once per frame
    138.     void Update()
    139.     {
    140.         animator.SetFloat("health", healtPercent);
    141.  
    142.         if (oponent != null)
    143.         {
    144.             animator.SetFloat("oponent_health", oponent.healtPercent);
    145.            
    146.  
    147.         }
    148.         else
    149.         {
    150.             animator.SetFloat("oponent_health", 1);
    151.            
    152.            
    153.  
    154.         }
    155.  
    156.         if (enable)
    157.         {
    158.             if (player == PlayerType.HUMAN)
    159.             {
    160.                 UpdateHumanInput();
    161.             }
    162.             else
    163.             {
    164.                 UpdateAiInput();
    165.             }
    166.  
    167.         }
    168.  
    169.         if (healt <= 0 && currentState != FighterStates.DEAD)
    170.         {
    171.             animator.SetTrigger("DEAD");
    172.            
    173.         }
    174.     }
    175.  
    176.     private float getDistanceToOponennt()
    177.     {
    178.         return Mathf.Abs(transform.position.x - oponent.transform.position.x);
    179.        
    180.     }
    181.  
    182.     public virtual void hurt(float damage)
    183.     {
    184.         if (!invulnerable)
    185.         {
    186.             if (defending)
    187.             {
    188.                 damage *= 0.2f;
    189.             }
    190.             if (healt >= damage)
    191.             {
    192.                 healt -= damage;
    193.             }
    194.             else
    195.             {
    196.                 healt = 0;
    197.             }
    198.  
    199.             if (healt > 0)
    200.             {
    201.                 animator.SetTrigger("TAKE_HIT");
    202.             }
    203.            
    204.  
    205.            
    206.            
    207.         }
    208.     }
    209.     public virtual void hurt2(float damage)
    210.     {
    211.         if (!invulnerable)
    212.         {
    213.            
    214.             if (healt >= damage)
    215.             {
    216.                 healt -= damage;
    217.             }
    218.             else
    219.             {
    220.                 healt = 0;
    221.             }
    222.  
    223.             if (healt > 0)
    224.             {
    225.                 animator.SetTrigger("TAKE_HITVolar");
    226.             }
    227.         }
    228.     }
    229.  
    230.  
    231.  
    232.     public void playSound(AudioClip sound)
    233.     {
    234.         GameUtils.playSound(sound, audioPlayer);
    235.     }
    236.  
    237.     public bool invulnerable
    238.     {
    239.         get
    240.         {
    241.             return currentState == FighterStates.TAKE_HIT
    242.                 || currentState == FighterStates.TAKE_HIT_DEFEND
    243.                 || currentState == FighterStates.TAKE_HITVolar
    244.                     || currentState == FighterStates.DEAD;
    245.         }
    246.     }
    247.  
    248.     public bool defending
    249.     {
    250.         get
    251.         {
    252.             return currentState == FighterStates.DEFEND
    253.                 || currentState == FighterStates.TAKE_HIT_DEFEND;
    254.         }
    255.     }
    256.  
    257.     public bool attacking
    258.     {
    259.         get
    260.         {
    261.             return currentState == FighterStates.ATTACK;
    262.            
    263.         }
    264.     }
    265.     public bool attackingVolar
    266.     {
    267.         get
    268.         {
    269.             return currentState == FighterStates.ATTACKVolar;
    270.         }
    271.     }
    272.     public float healtPercent
    273.     {
    274.         get
    275.         {
    276.             return healt / MAX_HEALTH;
    277.         }
    278.     }
    279.  
    280.     public Rigidbody body
    281.     {
    282.         get
    283.         {
    284.             return this.myBody;
    285.         }
    286.     }
    287. }
     
  23. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    It will be a lot of questions but it will be by part, there are 2 scripts I can assign

    (well not much of a question, sorry).
     
  24. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    if I understood what you wrote me.
     
  25. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Ok you still lost, the RoundTracker.cs should be alive on a GameObject, thats it. In your player script or whatever, when your health is 0, you can call the RecordRoundWinner method from the RoundTracker.cs like this
    Code (CSharp):
    1. RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left
    Side.Left being ken for example, if its ryu, use Side.Right, Now try this please, and see if it works
     
  26. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    hey, don't get mad, I'm going to ask you next,
    Code (CSharp):
    1. RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left
    I tried to put script fighter and it tells me error, sometimes I have a hard time understanding some things, if we have to go a little slowly
     
  27. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Error CS1519 The token "(" is invalid in a class, record, structure, or interface member declaration
    Error CS8124 A tuple must contain at least two elements.
    Error CS1026 Expected ) Assembly-CSharp
    Error IDE1007 The name 'RoundTracker.Instance.RecordRoundWinner' does not exist in the current context. Assembly-CSharp
    Error IDE1007 The name 'RoundTracker.Instance' does not exist in the current context. Assembly-CSharp
    Error IDE1007 The name 'Instance' does not exist in the current context.
    Error IDE1007 The name 'RecordRoundWinner' does not exist in the current context.
    Error IDE1007 The name 'RoundTracker.Side.Left' does not exist in the current context.
    Error IDE1007 The name 'Left' does not exist in the current context.
     
  28. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    if it is in GameObject, the script needs to know who is ryu left and ken right
     
  29. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    I just said it, since its offline, the script doesn't need to know, you need to know
    Code (CSharp):
    1. RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left
    If the winner is ryu, do that above, if its ken, change it from left to right
     
  30. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Like this? if not, make an arrow where I have to put ryu and ken.
     

    Attached Files:

  31. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I suspect that the language / Google Translate barrier is an issue here, but I'll try once more.

    - - -

    @TheFighterSFMK2022, have you done the Unity Essentials course, or any of the follow up courses? As I suggested here, where you were asking about the same project, and getting similar answers to the ones here.

    As I said there, you're not going to complete a game by hoping that passers by on the internet write your code for you.

    You need to learn the basics of C# and Unity and a few other things for yourself. That probably means putting aside the fighting game for a little bit and just studying your tools - Unity and C#. Or you're going to need to find an easier way to make a fighting game, such as the ones I suggested in that thread.

    On your current path, you need to know how variables work, what functions are, how to use branching and looping, what classes / objects are, how they are all used together, and how to use code to solve problems. And you need to be able to apply that in Unity. You can't skip this stuff. It's like trying to release a music album without knowing how to play any instruments.

    People aren't saying this stuff to be mean. We're saying it because it's how to do what you say you want to do. We don't know this stuff by magic, we know it because we spent time learning it, and that's what anyone would have to do.
     
    Johan_Liebert123 likes this.
  32. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    yes i did with lego microgame,
    and also, I don't know if you saw it in the 2.5D Small Fighting Game From Zero and I Need Your Help thread, which I told you how I increased the float with the animator for weak, medium and strong hits, maybe if he's right I'll leave it for a little bit the fighting game.
     
  33. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Johan_Liebert123 likes this.
  34. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I dont know? I think so?
     
  35. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Dude, when the round finishes and you want to record the winner, you can make
    Ken = Right
    Ryu = Left

    So if Ryu wins, you call this,
    Code (CSharp):
    1. if(health <= 0)
    2. {
    3.       RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left)
    4. }
    If ken wins, you call this
    Code (CSharp):
    1. if(health <= 0)
    2. {
    3.       RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Right)
    4. }
    NOTE - THIS ABOVE IS DONE IN YOUR PLAYER MANAGER SCRIPT OR GAME MANAGER SCRIPT, WHICH EVER ONE YOU HAVE
     
    TheFighterSFMK2022 likes this.
  36. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    One of them is 12 weeks long, so I doubt you'd have forgotten about doing it. Have you clicked the links I gave you to them?
     
    Johan_Liebert123 and Yoreki like this.
  37. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Dude, did I do it right?
    (find where it says //dude)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class BattleController : MonoBehaviour
    7. {
    8.     public int roundTime = 100;
    9.     private float lastTimeUpdate = 0;
    10.     private bool battleStarted;
    11.     private bool battleEnded;
    12.  
    13.     public Fighter player1;
    14.     public Fighter player2;
    15.     public BannerController banner;
    16.     public AudioSource musicPlayer;
    17.     public AudioClip backgroundMusic;
    18.  
    19.     public Image win;
    20.  
    21.     void Start()
    22.     {
    23.         banner.showRoundFight();
    24.         win.enabled = false;
    25.  
    26.     }
    27.    //Dude, here when the time ends
    28.     private void expireTime()
    29.     {
    30.         if (player1.healtPercent > player2.healtPercent)
    31.         {
    32.             player2.healt = 0;
    33.             win.enabled = false;
    34.             RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left);
    35.         }
    36.         else
    37.         {
    38.             player1.healt = 0;
    39.             win.enabled = true;
    40.             RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Right);
    41.         }
    42.     }
    43.  
    44.  
    45.  
    46.     void Update()
    47.     {
    48.         if (!battleStarted && !banner.isAnimating)
    49.         {
    50.             battleStarted = true;
    51.  
    52.             player1.enable = true;
    53.             player2.enable = true;
    54.  
    55.             GameUtils.playSound(backgroundMusic, musicPlayer);
    56.         }
    57.  
    58.         if (battleStarted && !battleEnded)
    59.         {
    60.             if (roundTime > 0 && Time.time - lastTimeUpdate > 1)
    61.             {
    62.                 roundTime--;
    63.                 lastTimeUpdate = Time.time;
    64.                 if (roundTime == 0)
    65.                 {
    66.                     expireTime();
    67.                 }
    68.             }
    69. //Dude, This way too
    70.             if (player1.healtPercent <= 0)
    71.             {
    72.                 banner.showYouLose();
    73.                 battleEnded = true;
    74.                 win.enabled = false;
    75.                 RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left);
    76.  
    77.             }
    78.             else if (player2.healtPercent <= 0)
    79.             {
    80.                 banner.showYouWin();
    81.                 battleEnded = true;
    82.                 win.enabled = true;
    83.                 RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Right);
    84.             }
    85.         }
    86.     }
    87. }
    88.  
    I feel like I did it right, but the image UI doesn't load when you restart it from the same scene,
     
  38. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    That looks good, have you tried it, does it work, use Debug.Log to see if the values are correct, display them on ui etc
     
  39. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I don't know where, like this?
    Code (CSharp):
    1.  
    2. if (player1.healtPercent <= 0)
    3.             {
    4.                 banner.showYouLose();
    5.                 battleEnded = true;
    6.                 win.enabled = false;
    7.                 RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Right);
    8.  
    9.                 Debug.Log("Win Ken");
    10.             }
    11.             else if (player2.healtPercent <= 0)
    12.             {
    13.                 banner.showYouWin();
    14.                 battleEnded = true;
    15.                 win.enabled = true;
    16.                
    17.                 RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left);
    18.                 Debug.Log("Win Ryu");
    19.             }
    20.  
     
  40. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I don't remember.
     
  41. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
  42. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    notation disappears
     
  43. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    There is a lot of great advice here, from very patient people who try to help, despite the problem you are trying to solve clearly being way over your current level of understanding. I agree with them, that you should start with the very basics. But at the very least try to understand that there is an edit button. You keep on posting like 2-5 times between each answer. That's highly irritating. It's spamm, literally.

    There can be valid reasons to post twice in a row, for example if you had a breakthrough, or found an answer to your previous question, or maybe even because youve spend the past half an hour to create a video. Sure. But dont make a new post for every 3 words you write. Just edit your old post to add what you forgot to say. There is absolutely no need or reason whatsoever, for why "I dont remember" and "perhaps yes (only one)" couldnt be in the same post.
     
    Nad_B, Ryiah and Johan_Liebert123 like this.
  44. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    I didn't know, the truth is that if I let them read it, if I wait for the answer, I think it's fine
     
  45. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    Code (CSharp):
    1. var rt = RoundTracker.Instance;
    2.             if (rt.FinalRound())
    3.             {
    4.                 var winsTally = $"{CurrentWinsOf(RoundTracker.Side.Left)} to {CurrentWinsOf(RoundTracker.Side.Right)}";
    5.                 Debug.Log($"After {rt.TotalRounds} rounds, the winner of the " +
    6.                           $"match was the player on the {rt.FinalWinner:G}, " +
    7.                           $"with the score of {winsTally}.");
    8.             }
    @Johan_Liebert123 Where do I put this? Fighter or BattleController?
     
  46. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Well what is it controlling? This is entirely up to how your scripts manage but it would most likely go in the battle controller because your ‘controlling’ the battle, checking for the last round
     
  47. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    we have problem
    Error CS0103 The name 'CurrentWinsOf' does not exist in the current context
    Error CS0103 The name 'CurrentWinsOf' does not exist in the current context
    Error CS1061 "RoundTracker" does not contain a definition for "FinalWinner" and does not contain an accessible extension method "FinalWinner" that accepts a first argument of type "RoundTracker" (are you missing a using directive or an assembly reference?)

    if we solve the roundtracker script that does work, I'll leave the fighting game for a while and rest.

    Code (CSharp):
    1. /*void Start() ?
    2.  
    3. or
    4.  
    5. private void expireTime()?
    6. {
    7.  
    8.         if (player1.healtPercent > player2.healtPercent)
    9.         {
    10.             player2.healt = 0;
    11.             win.enabled = false;
    12.             RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left);
    13.         }
    14.         else
    15.         {
    16.             player1.healt = 0;
    17.             win.enabled = true;
    18.             RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Right);
    19.         }
    20.     }
    21.  
    22.  
    23. void Update()?
    24. if (!battleStarted && !banner.isAnimating)?
    25.         {
    26.             battleStarted = true;
    27.  
    28.             player1.enable = true;
    29.             player2.enable = true;
    30.  
    31.             GameUtils.playSound(backgroundMusic, musicPlayer);
    32.         }
    33.  
    34.         if (battleStarted && !battleEnded)?
    35.         {
    36.            
    37.             if (roundTime > 0 && Time.time - lastTimeUpdate > 1)?
    38.             {
    39.                 roundTime--;
    40.                 lastTimeUpdate = Time.time;
    41.                 if (roundTime == 0)
    42.                 {
    43.                     expireTime();
    44.                 }
    45.             }
    46.  
    47.             if (player1.healtPercent <= 0)?
    48.             {
    49.                
    50.                 banner.showYouLose();
    51.                 battleEnded = true;
    52.                 win.enabled = false;
    53.                 RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Right);
    54.  
    55.                 Debug.Log("Win Ken");
    56.             }
    57.             else if (player2.healtPercent <= 0)?
    58.             {
    59.                 banner.showYouWin();
    60.                 battleEnded = true;
    61.                 win.enabled = true;
    62.                
    63.                 RoundTracker.Instance.RecordRoundWinner(RoundTracker.Side.Left);
    64.                 Debug.Log("Win Ryu");
    65.             }*/
    66.  
     
    Last edited: Oct 17, 2022
  48. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Trust me, leave it now, if you cant solve those errors, let alone know what they mean, you have barely no understanding of c#, I'm serious right now, stop what your doing, do what angrypenguin suggested, I don't care if you've done or not, your gonna do them now
     
    Nad_B likes this.
  49. TheFighterSFMK2022

    TheFighterSFMK2022

    Joined:
    Oct 1, 2022
    Posts:
    144
    (I came so close to making it work.):(
     
  50. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    'I' ???
     
    Nad_B and Yoreki like this.
Thread Status:
Not open for further replies.