So I’ve been working in Unity 1.6.2 and am trying to make a variation of the Health Pack script that deals damage. So the FPS walker runs into it and takes X damage.
The following is what I am using - changed the top Healthpack part basically, nothing else. I am clueless at coding so I am not sure what I can change and what i can/can’t delete.
Anyway when I implement this, I get the “All scripts need to successfully compile first!” error and do not understand what I need to change. Any help would be great!
enum PickupType { Health = 0, Rocket = 1 }
var pickupType = PickupType.Health;
var amount = 20;
var sound : AudioClip;
private var used = false;
function ApplyPickup (player : FPSPlayer)
{
if (pickupType == PickupType.Health)
{
if (player.hitPoints <= player.maximumHitPoints)
return true;
player.hitPoints -= amount;
player.hitPoints = Mathf.Min(player.hitPoints, player.maximumHitPoints);
}
else if (pickupType == PickupType.Rocket)
{
var launcher : RocketLauncher = player.GetComponentInChildren(RocketLauncher);
if (launcher)
launcher.ammoCount += amount;
}
return true;
}
function OnTriggerEnter (col : Collider) {
var player : FPSPlayer = col.GetComponent(FPSPlayer);
//* 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 || player == null)
return;
if (!ApplyPickup (player))
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;
}