Hello,
I was did health script but now when i have insert it hunger script i am getting error ‘Assets/Scripts/Playerhealth.js(17,22): BCE0044: expecting :, found ‘;’.’’
and the hunger is not working i dont know why its not showing variables on the inspector Here is my script
var MaxHealth = 100;
var Health : int;
var curHunger : int = 0;
var maxHunger : int = 10;
var Hungertext : GUIText;
function Start ()
{
Health = MaxHealth;
}
{
HungerRegen();
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
RespawnMenuV2.playerIsDead = true;
Debug.Log("Player Died");
}
function RespawnStats ()
{
Health = MaxHealth;
}
function Update ()
{
hungertext.text = "Hunger " + curHunger + " / " + maxHunger;
if(curHunger == 10 )
MaxHealth -= 5;
}
if(curHunger > maxHunger)
{
curHunger = maxHunger;
}
function HungerRegen ()
{
for(i=1;i>0;i++)
{
yield WaitForSeconds(1.0);
if(curHunger < maxHunger)
{
curHunger++;
}
}
}
Regards,
i3arty
Well for starts, match up your curly braces… you have extra ones in your Start function so you’re actually ending the function. Get rid of the { and } right before you call HungerRegen();
I have deleted these { } and now my script looks like this [below]
and i am getting several errors
Assets/Scripts/Playerhealth.js(54,5): BCE0005: Unknown identifier: ‘i’.
Assets/Scripts/Playerhealth.js(54,9): BCE0005: Unknown identifier: ‘i’.
Assets/Scripts/Playerhealth.js(54,13): BCE0005: Unknown identifier: ‘i’.
Assets/Scripts/HungerScript.js(15,14): BCE0051: Operator ‘-’ cannot be used with a left hand side of type ‘System.Type’ and a right hand side of type ‘int’.
#pragma strict
var MaxHealth = 100;
var Health : int;
var curHunger : int = 0;
var maxHunger : int = 10;
var Hungertext : GUIText;
function Start ()
{
Health = MaxHealth;
HungerRegen();
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
RespawnMenuV2.playerIsDead = true;
Debug.Log("Player Died");
}
function RespawnStats ()
{
Health = MaxHealth;
}
function Update ()
{
Hungertext.text = "Hunger " + curHunger + " / " + maxHunger;
if(curHunger == 10 )
MaxHealth -= 5;
}
if(curHunger > maxHunger)
{
curHunger = maxHunger;
}
function HungerRegen ()
{
for(i=1;i>0;i++)
{
yield WaitForSeconds(1.0);
if(curHunger < maxHunger)
{
curHunger++;
}
}
}
Thanks for helping!
You still have code outside of the Update function. Like Dustin suggested, line up the brackets properly. It makes it easier to trace your code for troubleshooting. Also, look at how you are doing the loop inside the function HungerRegen. You are not using the correct syntax for a for-loop, See here for details.