- Home /
Spinning Pointer that reacts when health drops
Hey all! So I have already had quite a bit of help with the need equation to get the spinner to move. But then I realized I had no idea how to combine the two pieces of information I have.
So I have this:
The Needle is its own object so that it may spin freely. Here is the sample of code I was given to power the spinner.
needle.transform.rotation = Quaternion.Euler( 0, needleDegreeOffset + health/maxHealth * needleDegreeRange, 0 );
And here is the script I am using to manage my character controller's health.
// These variables are used for the player's health
var curHP:float=100;
var maxHP:float=100;
// This is the player's money
var Money:int=0;
function ChangeHP(Change:float)
{
// This line will take whatever value is passed to this function and add it to curHP.
curHP+=Change;
// This if statement ensures that we don't go over the max health
if(curHP>maxHP)
{
curHP=100;
}
// This if statement is to check if the player has died
if(curHP<=0)
{
// Die
Debug.Log("Player has died!");
}
}
// This function checks if the player has entered a trigger
function OnTriggerEnter(other:Collider)
{
// The switch statement checks what tag the other gameobject is, and reacts accordingly.
switch(other.gameObject.tag)
{
case "Heal":
ChangeHP(25);
break;
case "Hurt":
ChangeHP(-25);
break;
case "Money":
Money+=25;
break;
}
// Finally, this line destroys the gameObject the player collided with.
Destroy(other.gameObject);
}
Now the part where I am lost is how to make these two pieces work when they are independent objects, one being the needle, and the other being the character controller that is in fact receiving the damage. Would the needle script be an entirely different script that references the health script? And if so, how would I connect them? Sorry for all the questions, still really new at scripting.
Thanks for the time and consideration!
Your answer
Follow this Question
Related Questions
Regain health on GUI 2 Answers
How to make a camera's background be another camera's veiw 1 Answer
Player health dropping far to fast 1 Answer
rect.width gets set to 0 for unknown reason 1 Answer
Help me with scripting please 1 Answer