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;
}
}
}