x


manabar doesnt work

my mana doesnt regenerate and i dont know if my health regenerates because i haven't made anything to make you lose health yet.

here is my script:

var lefthand : Transform;
var righthand : Transform;
var spell : GameObject;
var spell1 : GameObject;
var spell2 : GameObject;
var spell3 : GameObject;
var spell4 : GameObject;
var spell5 : GameObject;
var spell6 : GameObject;
var spell7 : GameObject;
var spell8 : GameObject;
var spell9 : GameObject;
var spell10 : GameObject;
var spell4u = 0;
var spell5u = 0;
var spell6u = 0;
var spell7u = 0;
var spell8u = 0;
var spell9u = 0;
var spell10u = 0;
var health = 100;
var mana = 100;
var dummy = 0;
var minusmana = 0;
var exp = 0;
var level = 0;
var maxHealth =100;
var maxmana =100;


function Start () {
spell = spell1;
Invoke("recharge", 0.1);
minusmana = 10;
}

function recharge () {
mana += 0.5;
health += 0.1;
Invoke("recharge", 0.1);
}

function manadown () {
mana -= minusmana;
}

function Update () {

maxHealth = level * 10 +100;
maxmana = level * 10 + 100;

if(Input.GetKeyDown("l")){
level += 1;
}
Debug.Log(level);


if(exp >= 100){
exp = 0;
level += 1;
}

if (mana >= maxHealth){
mana =  maxHealth;
}

if (health >= maxHealth){
health =  maxHealth;
}

if(Input.GetButtonDown("Fire1")){
if(mana >= minusmana){
Instantiate(spell, lefthand.position, lefthand.rotation);
Invoke("manadown",0);
}
}

if(Input.GetButtonDown("Fire2")){
if(mana >= minusmana){
Instantiate(spell, righthand.position, righthand.rotation);
Invoke("manadown",0);
}
}

if(Input.GetKeyDown("1")){
spell = spell1;
minusmana = 8;
}

if(Input.GetKeyDown("2")){
spell = spell2;
minusmana = 8;
}

if(Input.GetKeyDown("3")){
spell = spell3;
minusmana = 40;
}

if(Input.GetKeyDown("4")){
if(spell4u == 1);
spell = spell4;
minusmana = 10;
}

if(Input.GetKeyDown("5")){
if(spell5u == 1);
spell = spell5;
minusmana = 10;
}

if(Input.GetKeyDown("6")){
if(spell6u == 1);
spell = spell6;
minusmana = 10;
}

if(Input.GetKeyDown("7")){
if(spell7u == 1);
spell = spell7;
minusmana = 10;
}

if(Input.GetKeyDown("8")){
if(spell8u == 1);
spell = spell8;
minusmana = 10;
}

if(Input.GetKeyDown("9")){
if(spell9u == 1);
spell = spell9;
minusmana = 10;
}

if(Input.GetKeyDown("0")){
if(spell10u == 1);
spell = spell10;
minusmana = 10;
}
}

function OnGUI () {
GUI.color = Color.red;
  GUI.HorizontalScrollbar (Rect (Screen.width * 0.1, Screen.height * 0.85, maxHealth, 10), dummy, health, 0, maxHealth);
  GUI.color = Color.blue;
  GUI.HorizontalScrollbar (Rect (Screen.width * 0.1, Screen.height * 0.9, maxmana, 10), dummy, mana, 0, maxmana);
GUI.color = Color.yellow;
  GUI.HorizontalScrollbar (Rect (Screen.width * 0.1, Screen.height * 0.95, 180, 10), dummy, exp, 0, maxHealth);
}
more ▼

asked Dec 22 '11 at 11:15 AM

sam32x gravatar image

sam32x
178 42 57 63

why'd you dump this in a new question? you just asked the same thing in a different post a little while ago.

Dec 22 '11 at 11:18 AM Lo0NuhtiK

What a weirdly complicated way of implementing something really simple. Why are you doing it like that? You haven't even implemented all your core game mechanics and it's already impossible to read!

Dec 22 '11 at 11:20 AM syclamoth

@Lo0NuhtiK, I think the other question was another problem with the same code base. If you look at sams old code and compare it, they aren't the same.

Dec 22 '11 at 12:03 PM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

From the looks of it, mana and health are implicitly set as integers. You can't do stuff like + 0.1 with integers since they will round down to nearest integer.

Try changing your variables from

var health = 100;
var mana = 100;

to

var health : float = 100;
var mana : float = 100;

Also, you seem to have a typo. Can you spot it?

if (mana >= maxHealth) {
    mana = maxHealth;
}

I don't understand why you have if-tests that doesn't do anything. Are they placeholders for future code?

if (spell4u == 1);
more ▼

answered Dec 22 '11 at 12:10 PM

Statement gravatar image

Statement ♦♦
20.2k 35 71 176

if (spell4u == 1); yes im going to make it so you need to unlock the spell by getting to a certain level or buying it in the shop

Dec 22 '11 at 12:54 PM sam32x
(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:

x3419
x561
x99
x57
x11

asked: Dec 22 '11 at 11:15 AM

Seen: 670 times

Last Updated: Dec 26 '11 at 02:05 PM