hi im having a bit of a confusing time with this 1, im new to c# and unity but im learning as i go here, ive got a script for a mob to attack a player and it deducts from the players current health fine, now im trying to display the damage in a kind of floating combat text,
now ive got the text to display fine, im just unsure how to get the value that is being deducted and displaying that amount, ive commented the code as much as possible and im hoping someone can just point me in the right direction
using UnityEngine;
using System.Collections;
public class mobatt : MonoBehaviour {
public GameObject target;
public float attacktimer;
public int cooldown;
float Damagedisp;
private float scrollspeed; //scroll speed on the vertical
// Use this for initialization
void Start () {
attacktimer = ( Random.Range(1,3));
cooldown = ( Random.Range(1,3));
//---------
scrollspeed = Screen.height /2-10; //<--text scrolling
//---------
}
void OnGUI ()
{
GUI.Label ( new Rect(Screen.width/2-25, scrollspeed, 50, 50), Damagedisp.ToString()); <--this is the position of the scrolling text
}
// Update is called once per frame
void Update () {
if (attacktimer > 0)
attacktimer -= Time.deltaTime;
if (attacktimer < 0)
attacktimer = 0;
{
if (attacktimer == 0) {
attack ();
attacktimer = cooldown;
}
}
//------
scrollspeed -= Time.deltaTime*300; //<--scroll rate of the text
//------
}
private void attack() {
float distance = Vector3.Distance (target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position), normalized;
float direction = Vector3.Dot (dir, transform.forward);
if (distance < 2.0f) {
if (direction > 0.13) {
playerhp eh = (playerhp)target.GetComponent ("playerhp"); //this gets the value of the currenthp and the next line does the deductions
eh.adjcurhp (- Random.Range(1,5));
Damagedisp = 20; //<<<<<<---this is the part im having trouble with i cant seem to figure out what to put here, i was thinking Damagedisp = eh.adjcurhp but it doesnt seem to work
}
}
}
}
as i say i am very new to both unity and c# so i am willing to learn but obviously i need a little bit of guidance on the end bit,
thanks for any help on this 1