- Home /
Survival System Help
So im not that great at coding i have been trying to edit SpeedTutor Survival system. When the hunger or thirst goes to 0 the health starts decreasing but can someone please change it so that when the Hunger AND thirst have to be at 0 for the health to start decreasing. Sorry if it is to much to ask for but i have been trying to do it for some while now.
Survival Script :
#pragma strict
var currentHealth : float = 100.0;
var maxHealth : int = 100;
var currentThirst : float = 100.0;
var maxThirst : int = 100;
var currentHunger : float = 100.0;
var maxHunger : int = 100;
private var barLength = 0.0;
//FALL RATES (Higher = Slower)
var thirstFallRate : int = 4;
var hungerFallRate : int = 6;
//GUI Textures
var healthGood : Texture;
var healthNeutral : Texture;
var healthBad : Texture;
var thirstGood : Texture;
var thirstNeutral : Texture;
var thirstBad : Texture;
var hungerGood : Texture;
var hungerNeutral : Texture;
var hungerBad : Texture;
//GUI Booleans
private var guiHealthGood = false;
private var guiHealthNeutral = false;
private var guiHealthBad = false;
private var guiThirstGood = false;
private var guiThirstNeutral = false;
private var guiThirstBad = false;
private var guiHungerGood = false;
private var guiHungerNeutral = false;
private var guiHungerBad = false;
function Start()
{
barLength = Screen.width / 8;
}
function Update()
{
if(currentHealth <= 0)
{
CharacterDeath();
}
/* THIRST CONTROL SECTION*/
//Normal thirst degredation
if(currentThirst >= 0)
{
currentThirst -= Time.deltaTime / thirstFallRate;
}
if(currentThirst <= 0)
{
currentThirst = 0;
}
if(currentThirst >= maxThirst)
{
currentThirst = maxThirst;
}
/* HUNGER CONTROL SECTION*/
if(currentHunger >= 0)
{
currentHunger -= Time.deltaTime / hungerFallRate;
}
if(currentHunger <= 0)
{
currentHunger = 0;
}
if(currentHunger >= maxHunger)
{
currentHunger = maxHunger;
}
/* DAMAGE CONTROL SECTION*/
if(currentHunger <= 0 && (currentThirst <= 0))
{
currentHealth -= Time.deltaTime / 2;
}
else
{
if(currentHunger <= 0 || currentThirst <= 0)
{
currentHealth -= Time.deltaTime / 4;
}
}
/*NEW SECTION*/
if(currentHealth <= 100)
{
guiHealthGood = true;
guiHealthNeutral = false;
guiHealthBad = false;
}
if(currentHealth <= 50)
{
guiHealthGood = false;
guiHealthNeutral = true;
guiHealthBad = false;
}
if(currentHealth <= 25)
{
guiHealthGood = false;
guiHealthNeutral = false;
guiHealthBad = true;
}
/*NEW THIRST SECTION*/
if(currentThirst <= 100)
{
guiThirstGood = true;
guiThirstNeutral = false;
guiThirstBad = false;
}
if(currentThirst <= 50)
{
guiThirstGood = false;
guiThirstNeutral = true;
guiThirstBad = false;
}
if(currentThirst <= 25)
{
guiThirstGood = false;
guiThirstNeutral = false;
guiThirstBad = true;
}
/*NEW HUNGER SECTION*/
if(currentHunger <= 100)
{
guiHungerGood = true;
guiHungerNeutral = false;
guiHungerBad = false;
}
if(currentHunger <= 50)
{
guiHungerGood = false;
guiHungerNeutral = true;
guiHungerBad = false;
}
if(currentHunger <= 25)
{
guiHungerGood = false;
guiHungerNeutral = false;
guiHungerBad = true;
}
}
function CharacterDeath()
{
Application.LoadLevel("SimpleMenu");
}
function OnGUI()
{
//Health Icons
if(guiHealthGood == true)
{
GUI.DrawTexture(Rect(5, 30, 22.5, 33.75), healthGood);
}
if(guiHealthNeutral == true)
{
GUI.DrawTexture(Rect(5, 30, 22.5, 33.75), healthNeutral);
}
if(guiHealthBad == true)
{
GUI.DrawTexture(Rect(5, 30, 22.5, 33.75), healthBad);
}
//Thirst Icons
if(guiThirstGood == true)
{
GUI.DrawTexture(Rect(5, 55, 22.5, 33.75), thirstGood);
}
if(guiThirstNeutral == true)
{
GUI.DrawTexture(Rect(5, 55, 22.5, 33.75), thirstNeutral);
}
if(guiThirstBad == true)
{
GUI.DrawTexture(Rect(5, 55, 22.5, 33.75), thirstBad);
}
//Hunger Icons
if(guiHungerGood == true)
{
GUI.DrawTexture(Rect(5, 80, 22.5, 33.75), hungerGood);
}
if(guiHungerNeutral == true)
{
GUI.DrawTexture(Rect(5, 80, 22.5, 33.75), hungerNeutral);
}
if(guiHungerBad == true)
{
GUI.DrawTexture(Rect(5, 80, 22.5, 33.75), hungerBad);
}
//Health / Hunger / Thirst bars
GUI.Box(new Rect(55, 30, barLength, 23), currentHealth.ToString("0") + "/" + maxHealth);
GUI.Box(new Rect(55, 55, barLength, 23), currentThirst.ToString("0") + "/" + maxThirst);
GUI.Box(new Rect(55, 80, barLength, 23), currentHunger.ToString("0") + "/" + maxHunger);
}
Answer by Domo23000 · Jan 26, 2015 at 05:14 AM
if(currentHunger <= 0 && currentThirst <= 0)
{
currentHealth -= Time.deltaTime / 2;
}
else
{
if(currentHunger <= 0 || currentThirst <= 0)
{
currentHealth -= Time.deltaTime / 4;
}
}
In the damage control section this code can be deleted. It checks if the hunger or the thirst is under or at 0 then decreases gradually. The code before that checks if they are both at or below zero and depletes it twice as fast.
But I don't see you would want that because then you would only have to check your hunger or you thirst. you could just focus on getting food and not worry about water.
kk so when the hunger or thirst reaches 0 the health starts decreasing but what i need is the hunger and the thirst both have to be at 0 for the health to start decreasing.
no that is what this piece of code does.
if(currentHunger <= 0 && currentThirst <= 0)
{
currentHealth -= Time.deltaTime / 2;
}
you just remove this
else
{
if(currentHunger <= 0 || currentThirst <= 0)
{
currentHealth -= Time.deltaTime / 4;
}
}
this code is also really messy. i suggest you learn how to code and make your own. it's much easier to read since you made it, and it's just better for learning
Your answer
Follow this Question
Related Questions
Look On Cursor Problem 1 Answer
scripting error 1 Answer
C# Children of GameObject has it's script disabled after SetActive(false) and SetActive(true) 1 Answer
How can I create a random keycode generation ? 0 Answers
How to create a score manager script involving awarding points from multiple objects? 2 Answers