Hi,
I am trying to script an interaction between the player and a door. The door has a trigger-collider on it and I want it to open when the player makes contact with it, BUT ONLY IF the player’s essence (health) has reached a certain amount (at least 80); the process should then drain the player’s health by 80. The essence is controlled by a different script and counts up at the rate of 0.5 p/s. I think the particular problem I am having is in accessing the currentEssence from the essenceScript and then subtracting from it as currentEssence is a variable and -80 is an integer. I have exhausted the forums for similar problems. Help me Obi Wan Kenobi: you’re my only hope.
//essenceScript
var clockBG : Texture2D;
var clockFG : Texture2D;
var clockFGMaxWidth : float;
private var currentEssence : float;
var essenceRegen : float = 1;
function Start()
{
startTime = 10.0;
clockFGMaxWidth = clockFG.width;
currentEssence = 10;
}
function Update ()
{
currentEssence += essenceRegen * Time.deltaTime;
if(currentEssence >= 100) currentEssence = 100;
if(currentEssence <= 0) currentEssence = 0;
}
function OnGUI()
{
var newBarWidth:float = (currentEssence/100) * clockFGMaxWidth;
Debug.Log("current essence " + currentEssence);
var gap:int = 20;
GUI.BeginGroup(new Rect (Screen.width - clockBG.width - gap,
gap, clockBG.width, clockBG.height));
GUI.DrawTexture(Rect (0,0, clockBG.width, clockBG.height), clockBG);
GUI.BeginGroup(new Rect(5,6, newBarWidth, clockFG.height));
GUI.DrawTexture(Rect(0,0, clockFG.width, clockFG.height), clockFG);
GUI.EndGroup();
GUI.EndGroup();
}
//dooropener
private var currentEssence: essenceScript = GetComponent(essenceScript);
function OnTriggerEnter()
{
if (currentEssence >= 80) currentEssence -80;
yield WaitForSeconds (2);
Destroy(gameObject);
}