I was wondering how would I go about placing a script on a game object that would say “you have 80 health” based on this script. I’m not looking to make a GUI but just so that it will display “you have 80 HP” on a game object.
var hitpoints = 100;
var damage + 20;
function update () {
hitpoints -= damage:}
{
debug.Log(“your health is”) +hitpoints+
(“!”);
}
You can’t assign things like this when initializing a field.
var damage + 20;
The correct way to assign damage is this:
var damage = 20;
Now this wont work either, it has to be Update with a capital U, most programming languages are case sensitive
function update ()
{
This will work fine but it won't do what you want. This will take damage away from hitpoints almost instantly. Not the behaviour i expect you want.
hitpoints -= damage:
}
And this? Well this is dead code and would cause an error, why have you put curly braces around it?
{
Also this line, what on earth are you doing, this is no way syntactically correct.
debug.Log("your health is") +hitpoints+ ("!");
}
Now i have no idea what you want to achieve or how you are doing it, but i assume you want something like this:
var hitpoints = 100;
var damage = 20;
function ApplyDamage(){
hitpoints -= damage
Debug.Log("Your health is now " + hitpoints);
}
With this, what ever causes damage to your player will simply call ApplyDamage(). But judging by your code, you would not even understand how to do this.
Thank you for the help! I'm sorry I am new to programming as I am taking a computer game design class that has no prerequisites. I will look into programming basics in the link you posted.
Thank you for the help! I'm sorry I am new to programming as I am taking a computer game design class that has no prerequisites. I will look into programming basics in the link you posted.
– crowww