Health to come above enemy when clicked


So I have this script here that sends a message in order to show the health above the enemy as text:

var PoisonAttack : Texture; var AttackEnabled : boolean = false; var target : GameObject;

function OnGUI () {

if ( GUI.Button( Rect( 10, 10, 33, 32), PoisonAttack)) { //The button with the texture.

if ( PoisonAttackEnabled == true ) { //If the enemy has been targeted, allow the attack on target begin.

target.SendMessage (“ApplyPoisonAttack”, 32); //Sends a message to the enemy’s health with a value.

SendMessage (“PoisonAttackEnergy”, 15); //Sends a message to the players energy with a value.

target.BroadcastMessage (“AttackNumber”); //Sends a message to show the number as text.




//This is a message received by TargetEnemy.js enabling the attack and giving the correct target.

function PoisonAttackEnabled (EnemyTarget : GameObject) {

AttackEnabled = true;

target = EnemyTarget;


I have two problems.

The first is that the text i want shown is a random figure between 0 - 32 and the damage I do is also a random figure between 0 - 32, so the number won’t be the same, they will both be 2 different numbers between 0 and 32.

the second is that i cant work out how to show a random number using random.range as text, it says it can’t convert float to string. I have tried typecasting but it doesn’t seem to work.

Any answer is welcome, it doesn’t have to be correct, But I would at least like to have an alternative to showing numbers.

Check out the string formatting options in c# here: