Skip to content
Permalink
3070871771
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
128 lines (85 sloc) 2.85 KB
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerHits : MonoBehaviour {
public float PlayerHitPointsText = 0.0f;
public float PlayerDamage = 0.0f;
public float PlayerChanceToHit = 0.0f;
public float EnemyHitPoints = 0;
public float EnemyDamage = 0;
public float EnemyChanceToHit = 0.0f;
public Text pName;
public Text pDamage;
public Text pChance;
public Text eHits;
public Text eDamage;
public Text eChance;
public Text status;
public Text status2;
// Use this for initialization
void Start () {
Debug.Log (EnemyHitPoints);
}
public void RollStats () {
PlayerHitPointsText = Random.Range (4, 6);
PlayerDamage = Random.Range (1, 3);
PlayerChanceToHit = Random.Range (0, 100);
EnemyHitPoints = Random.Range (2, 8);
EnemyDamage = Random.Range (1,3);
EnemyChanceToHit = Random.Range (0, 100);
pName = pName.GetComponent<Text>();
pName.text = PlayerHitPointsText.ToString();
pDamage = pDamage.GetComponent<Text>();
pDamage.text = PlayerDamage.ToString();
pChance = pChance.GetComponent<Text>();
pChance.text = PlayerChanceToHit + "%".ToString();
eHits = eHits.GetComponent<Text>();
eHits.text = EnemyHitPoints.ToString();
eDamage = eDamage.GetComponent<Text>();
eDamage.text = EnemyDamage.ToString();
eChance = eChance.GetComponent<Text>();
eChance.text = EnemyChanceToHit + "%".ToString();
Debug.Log (EnemyHitPoints);
}
//player health - enemy damage
public void Fight() {
var roll = Random.Range (0.0f, 100.0f);
var playerstatus = "status";
var enemystatus = "status";
if (PlayerChanceToHit >= roll) {
EnemyHitPoints = EnemyHitPoints - PlayerDamage;
playerstatus = "You hit the enemy! Enemy Health is now " + EnemyHitPoints;
} else {
playerstatus = "You missed the enemy! Enemy Health is still " + EnemyHitPoints;
};
if (EnemyChanceToHit >= roll) {
PlayerHitPointsText = PlayerHitPointsText - EnemyDamage;
enemystatus = "The enemy hit you! Your health is now " + PlayerHitPointsText;
} else {
enemystatus = "The enemy missed you! Your health is still " + PlayerHitPointsText;
};
status = status.GetComponent<Text> ();
status.text = playerstatus.ToString ();
status2 = status2.GetComponent<Text> ();
status2.text = enemystatus.ToString ();
if (EnemyHitPoints <= 0) {
enemystatus = "";
playerstatus = "You won!";
status = status.GetComponent<Text> ();
status.text = playerstatus.ToString ();
status2 = status2.GetComponent<Text> ();
status2.text = enemystatus.ToString ();
};
if (PlayerHitPointsText <= 0) {
enemystatus = "";
playerstatus = "You Lost";
status = status.GetComponent<Text> ();
status.text = playerstatus.ToString ();
status2 = status2.GetComponent<Text> ();
status2.text = enemystatus.ToString ();
};
}
// Update is called once per frame
void Update () {
}
}