Question by
maliiio · Jul 15, 2017 at 04:20 PM ·
c#monodevelopunity 4.6
Button doesn't work on specific part of the game
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GameScript : MonoBehaviour {
public Text warrior;
public Text whealth;
public Text ehealth;
private enum States {gamescene, fight_begins, fight_scene, heavyattack }
private States myState;
int ehmax = 29;
int ehmin = 23;
int hamax = 8;
int hamin = 6;
int ha;
int ave;
void Start () {
myState = States.gamescene;
ave = Random.Range (ehmax +1, ehmin);
ha = Random.Range (hamax +1, hamin);
}
// Update is called once per frame
void Update () {
if (myState == States.gamescene) {gamescene();}
else if (myState == States.fight_begins) {fightbegins();}
else if (myState == States.fight_scene) {fightscene();}
else if (myState == States.heavyattack) {heavyattack();}
}
void gamescene () {
warrior.text = "You are a warrior, patroling around King's Landing and suddenly you see another man hidings inside the bushes\n\n" +
"Press Return (Enter) to continue" ;
if (Input.GetKeyDown(KeyCode.Return)) {myState = States.fight_begins;}
}
void fightbegins () {
warrior.text = "You approach to him and he attacks you, obviously he was waiting for you. You back off a little and you wield " +
"your sword, and the fight begins.\n\n" + "Press Return to continue";
if (Input.GetKeyDown(KeyCode.Return)) {myState = States.fight_scene;}
}
void fightscene () {
warrior.text = "You both take position and look into each other's eyes with a fierce look. You both know that one of you will " +
"die today.\n\n" + "Attack using the buttons below, remember; heavy attack has a chance of backfiring and " +
"hurting you";
if(Input.GetKeyDown(KeyCode.Return)) {myState = States.heavyattack;}
whealth.text = "Your Health: 25";
ehealth.text = ( "Enemy Health: " + ave.ToString());
}
public void hattack () {
myState = States.heavyattack;
}
void heavyattack() {
int newhalth = ave - ha;
warrior.text = "You hit the enemy with a heavy attack" ;
Debug.Log("Entered");
ehealth.text = ( "Enemy Health: " + newhalth.ToString()) ;
}
}
That's my code. Sorry, I am just really beginner. Basicly what I want to do is, change the enemy health when I press heavy attack. It works on the first levels(parts, not actual scenes), but when I go to the last level, It simply doesn't work. I checked if I can call it with If(Input.GetKeyDowm) function and It works. So please help me, what's wrong? (Version is Unity 4.6)
adsız.png
(196.9 kB)
adsız1.png
(221.9 kB)
Comment
Your answer
Follow this Question
Related Questions
UnityEngine .DLL files are buried under Managed/UnityEngine/ 0 Answers
UnityEngine.UI is not working. 2 Answers
Unity 4 error loading page 0 Answers