- Home /
i need help with a random number health script
hey i need help with my healt script it has to do random damage but it doesen't work so pleas help me . Here is my code
#pragma strict var health : int = 100; static var seed : int ; var myDouble : float = 100; function Start () { health -= myDouble; } function damage () { myDouble = (Random.Range(1, 300) == 1 ? -0.1 : -0.3); }
Answer by xander · May 19, 2012 at 05:11 PM
hey thanks for your awnser i am new so i dident know how to do randomize numbers
Answer by Piflik · May 18, 2012 at 09:21 PM
Is that the whole script? How are you calling the damage function?
You subtract myDouble from health at startup and then you assign myDouble a new value on damage...that doesn't make much sense...or I don't see it.
I would do something like this:
var health : float = 100.0;
function damage() {
health -= Random.Range(1, 300) == 1 ? 0.1 : 0.3;
}
So, you're not even going to ask if this is supposed to do 0.1 damage 99.66% of the time, to an int?
Your answer
Follow this Question
Related Questions
How to make death messages show at random? 1 Answer
instantiate objects randomly and unique to fixed positions 0 Answers
How do I randomize 5 prefabs on Scene loaded? 1 Answer
Randomly remove list values 1 Answer
Randomize texture within prefab 0 Answers