BCE0020 - Instance Type Error

Hello,

When I try to compile I get an error saying "Instance of type 'PlayerHealth' is required to access static member 'AdjustCurrentHealth'".

The AdjustCurrentHealth function is in a js file called PlayerHealth and it's expecting a int to be passed.

I guess I'm trying to link to the function improperly but not sure how to fix it. Thanks for any help you can offer.

static var GEAR_COUNT = 0;

function OnTriggerEnter (other : Collider) 
{
     if(other.gameObject.CompareTag ("Battery"))
    {
        // Add Battery To Player's Life
        PlayerHealth.AdjustCurrentHealth(25);
        print("You've Collected A Battery");

        // Destroy The Battery
        Destroy(other.gameObject);
    }
}

That's because right now, you're trying to call the function on the script directly. This will never work. What you need to do is create an instance of the script on a gameObject. Then, you get a reference to that instance, and finally, you call the function on that instance. Your script would look like this:

var playerHealthInstance : PlayerHealth;
static var GEAR_COUNT = 0;

function Start() {
    playerHealthInstance = GameObject.Find("Player").GetComponent(PlayerHealth);
}

function OnTriggerEnter (other : Collider) 
{
     if(other.gameObject.CompareTag ("Battery"))
    {
        // Add Battery To Player's Life
        playerHealthInstance.AdjustCurrentHealth(25);
        print("You've Collected A Battery");

        // Destroy The Battery
        Destroy(other.gameObject);
    }
}

You'll need to add the PlayerHealth script to the player for this to work, obviously. Of course, you'll also want to replace Player in GameObject.Find("Player") with the actual name of your player, as the Find command looks for an object by name.

Please note, the above script is untested and may contain errors.