I’m using a pickup script from the third person sample pack that’s on the unity’s community site. I suck at javascript, and I’m trying to add a pickup type, but I just don’t know where to even begin. Here’s the code I’m working with:
enum PickupType { Health = 0, ExtraLife = 1 }
var pickupType = PickupType.Health;
var amount = 1;
var sound : AudioClip;
private var used = false;
function ApplyPickup (health : ThirdPersonHealth)
{
if (pickupType == PickupType.Health)
{
if (health.health >= health.maxHealth)
return false;
health.AddHealth(amount);
}
else if (pickupType == PickupType.ExtraLife)
{
health.AddLife(amount);
}
return true;
}
function OnTriggerEnter (col : Collider) {
var health : ThirdPersonHealth = col.GetComponent(ThirdPersonHealth);
//* Make sure we are running into a player
//* prevent picking up the trigger twice, because destruction
// might be delayed until the animation has finnished
if (used || health == null)
return;
if (!ApplyPickup (health))
return;
used = true;
// Play sound
if (sound)
AudioSource.PlayClipAtPoint(sound, transform.position);
// If there is an animation attached.
// Play it.
if (animation animation.clip)
{
animation.Play();
Destroy(gameObject, animation.clip.length);
}
else
{
Destroy(gameObject);
}
}
// Auto setup the pickup
function Reset ()
{
if (collider == null)
gameObject.AddComponent(BoxCollider);
collider.isTrigger = true;
}
@script AddComponentMenu("Third Person Props/Pickup")
Any help is appreciated.