I am trying to add a scoring system to the Lerpz Escapes game. I have tried doing a few things but no matter what I change, its not working. Still learning javascript as well. For those of you that have done the Lerpz guide, I have added scoring to the Pickup script.
Pickup Script:
enum PickupType { Health = 0, FuelCell = 1 }
var pickupType = PickupType.FuelCell;
var amount = 1;
var sound : AudioClip;
var soundVolume : float = 2.0;
static var myScore : int = 0;
private var used = false;
private var mover : DroppableMover;
function Start ()
{
mover = GetComponent(DroppableMover);
}
function ApplyPickup (playerStatus : ThirdPersonStatus)
{
switch (pickupType)
{
case PickupType.Health:
playerStatus.AddHealth(amount);
break;
case PickupType.FuelCell:
playerStatus.FoundItem(amount);
break;
}
return true;
}
function OnTriggerEnter (col : Collider) {
if(mover && mover.enabled) return;
var playerStatus : ThirdPersonStatus = col.GetComponent(ThirdPersonStatus);
if (used || playerStatus == null)
return;
if (!ApplyPickup (playerStatus))
return;
used = true;
myScore += 1;
if (sound)
AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
if (animation && animation.clip)
{
animation.Play();
Destroy(gameObject, animation.clip.length);
}
else
{
Destroy(gameObject);
}
}
function Reset ()
{
if (collider == null)
gameObject.AddComponent(BoxCollider);
collider.isTrigger = true;
}
@script RequireComponent(SphereCollider)
@script AddComponentMenu("Third Person Props/Pickup")
Then I created another script called Scoring and it looks like this:
@script RequireComponent(GUIText)
var myScore : float = 0;
function Update () {
guiText.text = "Score : " +myScore;
transform.position.x = .15;
transform.position.y = .91;
}
So, when I load the game, I see the word "Score : 0" but whenever I pickup an item, the score does not change. So, I think something is wrong with the Pickup script that I updated. My goal is to make it so when you pickup a FuelCell you get 5 points and the hearts you get 10 points, but first I just want to get it working. Again, I am still learning javascript, so please provide as many details as possible. Thanks for the help!