How to go to the next round

Hi, I need advice. I can’t advance to the second round. I need to go to the next round
I wanted to do my own round, I need someone to guide me with this

using UnityEngine;
using System.Collections;

public class BattleController : MonoBehaviour {
    public int roundTime = 100;
    private float lastTimeUpdate = 0;
    private bool battleStarted;
    private bool battleEnded;

    public Fighter player1;
    public Fighter player2;
    public BannerController banner;
    public AudioSource musicPlayer;
    public AudioClip backgroundMusic;

    // Use this for initialization
    void Start () {
        banner.showRoundFight ();
    }

    private void expireTime(){
        if (player1.healtPercent > player2.healtPercent) {
            player2.healt = 0;
        } else {
            player1.healt = 0;
        }
    }
  
    // Update is called once per frame
    void Update () {
        if (!battleStarted && !banner.isAnimating) {
            battleStarted = true;

            player1.enable = true;
            player2.enable = true;

            GameUtils.playSound(backgroundMusic, musicPlayer);
        }

        if (battleStarted && !battleEnded) {
            if (roundTime > 0 && Time.time - lastTimeUpdate > 1) {
                roundTime--;
                lastTimeUpdate = Time.time;
                if (roundTime == 0){
                    expireTime();
                }
            }

            if (player1.healtPercent <= 0) {
                banner.showYouLose ();
                battleEnded = true;

            } else if (player2.healtPercent <= 0) {
                banner.showYouWin ();
                battleEnded = true;
            }
        }
    }
}

this is the player’s fighter script. ( Health )

using UnityEngine;
using System.Collections;

public class Fighter : MonoBehaviour {
    public enum PlayerType
    {
        HUMAN, AI  
    };

    public static float MAX_HEALTH = 100f;

    public float healt = MAX_HEALTH;
    public string fighterName;
    public Fighter oponent;
    public bool enable;

    public PlayerType player;
    public FighterStates currentState = FighterStates.IDLE;

    protected Animator animator;
    private Rigidbody myBody;
    private AudioSource audioPlayer;

    //for AI only
    private float random;
    private float randomSetTime;
  
    // Use this for initialization
    void Start () {
        myBody = GetComponent<Rigidbody> ();
        animator = GetComponent<Animator> ();
        audioPlayer = GetComponent<AudioSource> ();
    }

    public void UpdateHumanInput (){
        if (Input.GetAxis ("Horizontal") > 0.1) {
            animator.SetBool ("WALK", true);
        } else {
            animator.SetBool ("WALK", false);
        }

        if (Input.GetAxis ("Horizontal") < -0.1) {
            if (oponent.attacking){
                animator.SetBool ("WALK_BACK", false);
                animator.SetBool ("DEFEND", true);
            }else{
                animator.SetBool ("WALK_BACK", true);
                animator.SetBool ("DEFEND", false);
            }
        } else {
            animator.SetBool ("WALK_BACK", false);
            animator.SetBool ("DEFEND", false);
        }

        if (Input.GetAxis ("Vertical") < -0.1) {
            animator.SetBool ("DUCK", true);
        } else {
            animator.SetBool ("DUCK", false);
        }

        if (Input.GetKeyDown (KeyCode.UpArrow)) {
            animator.SetTrigger("JUMP");
        }

        if (Input.GetKeyDown (KeyCode.Space)) {
            animator.SetTrigger("PUNCH");
        }

        if (Input.GetKeyDown (KeyCode.K)) {
            animator.SetTrigger("KICK");
        }

        if (Input.GetKeyDown (KeyCode.H)) {
            animator.SetTrigger("HADOKEN");
        }
    }

    public void UpdateAiInput (){
        animator.SetBool ("defending", defending);
        //animator.SetBool ("invulnerable", invulnerable);
        //animator.SetBool ("enable", enable);

        animator.SetBool ("oponent_attacking", oponent.attacking);
        animator.SetFloat ("distanceToOponent", getDistanceToOponennt());

        if (Time.time - randomSetTime > 1) {
            random = Random.value;
            randomSetTime = Time.time;
        }
        animator.SetFloat ("random", random);
    }
  
    // Update is called once per frame
    void Update () {
        animator.SetFloat ("health", healtPercent);

        if (oponent != null) {
            animator.SetFloat ("oponent_health", oponent.healtPercent);
        } else {
            animator.SetFloat ("oponent_health", 1);
        }

        if (enable) {
            if (player == PlayerType.HUMAN) {
                UpdateHumanInput ();
            }else{
                UpdateAiInput();
            }

        }

        if (healt <= 0 && currentState != FighterStates.DEAD) {
            animator.SetTrigger ("DEAD");
        }
    }

    private float getDistanceToOponennt(){
        return Mathf.Abs(transform.position.x - oponent.transform.position.x);
    }

    public virtual void hurt(float damage){
        if (!invulnerable) {
            if (defending){
                damage *= 0.2f;
            }
            if (healt >= damage) {
                healt -= damage;
            } else {
                healt = 0;
            }

            if (healt > 0) {
                animator.SetTrigger ("TAKE_HIT");
            }
        }
    }

    public void playSound(AudioClip sound){
        GameUtils.playSound (sound, audioPlayer);
    }

    public bool invulnerable {
        get {
            return currentState == FighterStates.TAKE_HIT
                || currentState == FighterStates.TAKE_HIT_DEFEND
                    || currentState == FighterStates.DEAD;
        }
    }

    public bool defending {
        get {
            return currentState == FighterStates.DEFEND
                || currentState == FighterStates.TAKE_HIT_DEFEND;
        }
    }

    public bool attacking {
        get {
            return currentState == FighterStates.ATTACK;
        }  
    }

    public float healtPercent {
        get {
            return healt / MAX_HEALTH;
        }  
    }

    public Rigidbody body {
        get {
            return this.myBody;
        }
    }
}

I’m not sure this script can make the wrestler wins the round show up

using UnityEngine;
using System.Collections;

public class BannerController : MonoBehaviour {

    private Animator animator;
    private AudioSource audioPlayer;

    private bool animating;

    // Use this for initialization
    void Start () {
        animator = GetComponent<Animator> ();
        audioPlayer = GetComponent<AudioSource> ();

    }

    public void showRoundFight(){
        animating = true;
        animator.SetTrigger ("SHOW_ROUND_FIGHT");
    }

    public void showYouWin(){
        animating = true;
        animator.SetTrigger ("SHOW_YOU_WIN");
    }

    public void showYouLose(){
        animating = true;
        animator.SetTrigger ("SHOW_YOU_LOSE");
    }

    public void playVoice(AudioClip voice){
        GameUtils.playSound (voice, audioPlayer);
    }

    public void animationEnded(){
        animating = false;
    }

    public bool isAnimating{
        get{
            return animating;
        }
    }
}

It’s always more than just some code… there’s how you do it and integration with the scene, etc.

You’re welcome to look at my DemoTwinStickShooter game in my proximity buttons package.

The code in question starts at line 243 here in this file:

https://github.com/kurtdekker/proximity_buttons/blob/master/proximity_buttons/Assets/DemoTwinStickShooter/TwinStickGameManager.cs

There is only Pre-wave and playing and game over. But with that pattern you can add extra phases and change it to whatever your game needs easily.

proximity_buttons is presently hosted at these locations:

https://bitbucket.org/kurtdekker/proximity_buttons

https://github.com/kurtdekker/proximity_buttons

https://gitlab.com/kurtdekker/proximity_buttons

https://sourceforge.net/projects/proximity-buttons/

If you want other ways of doing it, definitely hit Youtube tutorials for any game that has levels or stages or rounds or whatever. It’s all the same idea, a sequence like:

  • suspend activity
  • notify
  • wait
  • resume activity

here it says.

To open your project, install Editor version 5.6.6f2 or select a different version below. Please note: using a different Editor version than the one your project was created with may introduce risks.

I only have the version of
2021.3.0f1
2020.3.10f1
2018.1.3f1
of unity, which version do i choose?

Don’t worry about that. It should upgrade just fine.

an error came out version 2018.1.3f1

wait for me a moment.

no, it still doesn’t work.

8760313--1187545--Captura de pantalla 2023-01-27 005558.png

If you look at Unity - Manual: Android JNI you’ll see that that package was first introduced (or at least first got documentation) in Unity 2019.2
Any version after that should work (if the package is actually required).

To go next round you need to revert your game state to the origin, so reset player health, position etc…

So make a function that just do that, and call it when the round is over. If you want to test it before the round is actually is over just make an insta-win or insta-lose button.

1 Like

Extra unwanted packages in new projects (collab, testing, rider and other junk):

https://discussions.unity.com/t/846703/2

About the fastest way I have found to make a project and avoid all this noise is to create the project, then as soon as you see the files appear, FORCE-STOP (hard-kill) Unity (with the Activity Manager or Task Manager), then go hand-edit the Packages/manifest.json file as outlined in the above post, then reopen Unity.

Sometimes the package system gets borked from all this unnecessary churn and requires the package cache to be cleared:

https://stackoverflow.com/questions/53145919/unity3d-package-cache-errors/69779122

thanks your advice. @dlorre

and you too. @SF_FrankvHoof

@dlorre a small question, can you also make a game manager script for the fight round? Why haven’t I created a game manager (question a little funny):).

@Kurt-Dekker I tried your project yesterday, I thought it was a fighting game but I didn’t notice the name of your folder DemoTwinStickShooter;). but if I started to play your project (good project). I will try copying your DemoTwinStickShooter scripts if it works or not.

Isn’t your BattleController enough?

    public void NextRound()
    {
        player1.ResetStats();
        player2.ResetStats();
        battleEnded = false;
        battleStarted = true;
        // add whatever else you need
    }

Now your next problem is how to call NextRound(), this can be done after a delay when you show the banner, or you can display an UI Button labelled “Next Round” and restart when it’s clicked.

1 Like

Oh Ok

how should i create public or private a ResetStats(); It gives me an error. I did it exactly as the script passed it to me.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

1 Like

Yeah, I didn’t give you all the code. You have a class Fighter, it is where you declare ResetStats, public void will be fine.

1 Like

Thanks:), I think this idea what I’m thinking could work.

Script Fighter.

 // ResetStats
    public Vector3 StartPoint;
    public void ResetStats()
    {
        transform.position = StartPoint;
    }

Script BattleController.
public void NextRound()
{
player2.ResetStats();
player1.ResetStats();

battleEnded = false;
battleStarted = true;
// add whatever else you need
}

Script BannerController.
// “SHOW YOU WIN”
public BattleController battleController;

void NextRoundOfWin()
{
battleController.NextRound();
}

a video that would be the idea;)

https://www.youtube.com/watch?v=-2v_rzvKN_w

and now I wonder if I create a UI an image of ryu in the life rod and how to return to animator idle.

1 Like

You also might want to set the player hps back to max when you reset stats.

1 Like

Thank you, but now a problem arises, now you can’t raise the life rod, you can only change the numbers in the inspector, later I find a solution, now I want to make ryu come back, he’s idle

what is hps?:smile:

hps is short for hit points, it’s your health variable in your script. Your state:

public FighterStates currentState = FighterStates.IDLE;

This should also be reset in ResetStats(), you need to find everything that must be done to return to start position.

1 Like

I already know why.

8764792--1188589--upload_2023-1-29_7-45-32.png

8764792--1188592--upload_2023-1-29_7-47-9.png

public FighterStates currentState = FighterStates.IDLE;

and this is what will happen without putting
public FighterStates currentState = FighterStates.IDLE;
in ResetStats()

https://www.youtube.com/watch?v=rChZpXaUu78

what I need is that when I say round 2 it doesn’t move until I say fight, if I put animationEnded() but it will still be activated.

I think

public void NextRound()
    {
        roundTime = 100;
        player2.ResetStats();
        player1.ResetStats();
      
 // battleEnded & battleStarted has to have worked the script, or not.
        battleEnded = false;
        battleStarted = true;
    
    }

I don’t know why.