x


Health to come above enemy when clicked

OK,

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.

more ▼

asked Feb 06 '12 at 08:33 PM

MithosAnnar gravatar image

MithosAnnar
299 22 36 41

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Check out the string formatting options in c# here:

http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.71).aspx

more ▼

answered Feb 07 '12 at 02:59 AM

tingham gravatar image

tingham
660 2 7 13

thanks, I got it working.

Feb 07 '12 at 01:20 PM MithosAnnar
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x700
x672
x394
x81
x36

asked: Feb 06 '12 at 08:33 PM

Seen: 635 times

Last Updated: Feb 07 '12 at 01:20 PM