Hello, I’m trying to make a coin in my game. So far I’ve been able to collect the coin (player touches coin, coin disappears) but the GUI doesn’t register that I’ve collected a coin. I looked around in the scripts and I can’t seem to find the error. Any help would be greatly appreciated.
Thanks,
zAk
the Pickup script (attached to coin)
enum PickupType { Health = 0, FuelCell = 1 }
var amount = 1;
var sound : AudioClip;
var soundVolume : float = 2.0;
var CoincounterComponent: Component;
var pickupType = PickupType.Coin;
private var used = false;
function Start ()
{
// do we exist in the level or are we instantiated by an enemy dying?
mover = GetComponent(DroppableMover);
}
function ApplyPickup (playerStatus : ThirdPersonStatus)
{
CoincounterComponent = GetComponent("Coincounter");
switch (pickupType)
{
case PickupType.Coin:
playerStatus.FoundItem(amount);
break;
// A switch...case statement may seem overkill for this, but it makes adding new pickup types trivial.
case PickupType.Coin:
playerStatus.FoundItem(amount);
break;
}
return true;
}
function OnTriggerEnter (col : Collider) {
if(DroppableMover DroppableMover.nabled) return;
var playerStatus : ThirdPersonStatus = col.GetComponent(ThirdPersonStatus);
//* Make sure we are running into a player
//* prevent picking up the trigger twice, because destruction
// might be delayed until the animation has finished
if (used || playerStatus == null)
return;
if (!ApplyPickup (playerStatus))
return;
used = true;
// Play sound
if (sound)
AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
// 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 RequireComponent(SphereCollider)
@script AddComponentMenu("Third Person Props/Pickup")
The Coincounter script (attached to camera)
static var pointCoin : int = 0;
function Start ( ) {
GameHUDComponent = GetComponent(GameHUD);
}
function OnGUI( ) {
GUI.Label (Rect (10, 10, 100, 20), "Coins: " + pointCoin);
}