How can I get an item to add health to a player?

Okay so I have an item that I want to add ten health to a player’s current health. Here is the script I wrote for it.

#pragma strict

var PlayerDude : PlayerStats;
static var HealthPlus = 10;
private var DrawGUI = false;

function Start()
{
	PlayerDude = GameObject.Find("Player").GetComponent(PlayerStats);
}

function OnTriggerEnter (theCollider : Collider)
{
	if (theCollider.tag == "Player")
	{
	DrawGUI = true;
	}
	
	if(DrawGUI == true && Input.GetKeyDown(KeyCode.E))
	{
		HealthUp();
	}
}


function OnTriggerExit (theCollider : Collider)
{
	if (theCollider.tag == "Player")
	{
	DrawGUI = false;
	}
}

function OnGUI ()
{
	if (DrawGUI == true)
	{

	GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Press E to Drink");
	
	}
}

function HealthUp () 
{
	SendMessage("AddHealth", HealthPlus, SendMessageOptions.DontRequireReceiver);
}

I am fairly new to Unity, and very new to Javascript so this is my first piece of script I’ve tried to write on my own completely. But for some reason I just can’t get it to add the health to the player. Here is the code to the player’s stats too.

#pragma strict

var MaxHealth = 100;
var Health : int;

function Start()
{
	Health = MaxHealth;
}

function ApplyDamage (TheDamage : int)
{
	Health -= TheDamage;
	
	if (Health <= 0)
	{
		Dead();
	}
}

function Dead()
{	
	RespawnMenuV2.PlayerIsDead = true;
	Debug.Log("You have died");
}

function RespawnStats()
{
	Health = MaxHealth;
}

function AddHealth (HealthUp : int)
{
	Health += HealthUp;
}

I’m really working at it, but its seems I’m stuck. Any help with someone who can figure this out is greatly appreciated :slight_smile:

you have function PlayerStats on your script, just call addHealth function…

if(DrawGUI == true && Input.GetKeyDown(KeyCode.E))
{
   PlayerDude.AddHealth(HealthPlus);
}

or inside of HealthUp function, if you really need it…