Okay, so, in a way this is a continuation of my last post which involved swapping out Char A with Char B. Now, I’m using the Lerpz Tutorial script “Pickup” to have my character pick up different colored Gems.
Now, when the character starts out, he is able to pick up the gems and they properly increase the values on the Gem Counter Panel. However, when I switch forms, the Gems no longer increase the values on the counter panel, despite disappearing on Collision.
Furthermore, if I switch the forms BACK, the first form also cannot pick up the gems. What is going on here?
I suspect it has something to do with both Characters having the script “ThirdPersonStatus”, but the game is only able to recognize them one at a time. But I’m not sure. Any help is greatly appreciated!
Pickup:
enum PickupType { Health = 0, BlueGem = 1, YellowGem = 2, GreenGem = 3, RedGem = 4 }
var pickupType = PickupType.BlueGem;
var amount = 1;
var sound : AudioClip;
var soundVolume : float = 2.0;
private var used = false;
private var mover : DroppableMover;
function Start ()
{
// do we exist in the level or are we instantiated by an enemy dying?
mover = GetComponent(DroppableMover);
}
function ApplyPickup (playerStatus : ThirdPersonStatus)
{
// A switch...case statement may seem overkill for this, but it makes adding new pickup types trivial.
switch (pickupType)
{
case PickupType.Health:
playerStatus.AddHealth(amount);
break;
case PickupType.BlueGem:
playerStatus.FoundBlue(amount);
break;
case PickupType.YellowGem:
playerStatus.FoundYellow(amount);
break;
case PickupType.GreenGem:
playerStatus.FoundGreen(amount);
break;
case PickupType.RedGem:
playerStatus.FoundRed(amount);
break;
}
return true;
}
function OnTriggerEnter (col : Collider) {
if(mover mover.enabled) 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")
ThirdPersonStatus
// ThirdPersonStatus: Handles the player's state machine.
// Keeps track of inventory, health, lives, etc.
var health : int = 6;
var maxHealth : int = 6;
var lives = 4;
// sound effects.
var struckSound: AudioClip;
var deathSound: AudioClip;
private var levelStateMachine : LevelStatus; // link to script that handles the level-complete sequence.
private var BlueGemsOwned : int; // Number of BlueGems the player has. Grabbed from LevelStatus.
private var YellowGemsOwned: int;
private var GreenGemsOwned: int;
private var RedGemsOwned: int;
function Awake()
{
levelStateMachine = FindObjectOfType(LevelStatus);
if (!levelStateMachine)
Debug.Log("No link to Level Status");
remainingBlue = levelStateMachine.BlueGemsOwned;
}
// Utility function used by HUD script:
function GetRemainingBlue() : int
{
return BlueGemsOwned;
}
function GetRemainingYellow() : int
{
return YellowGemsOwned;
}
function GetRemainingGreen() : int
{
return GreenGemsOwned;
}
function GetRemainingRed() : int
{
return RedGemsOwned;
}
function ApplyDamage (damage : int)
{
if (struckSound)
AudioSource.PlayClipAtPoint(struckSound, transform.position); // play the 'player was struck' sound.
health -= damage;
if (health <= 0)
{
SendMessage("Die");
}
}
function AddLife (powerUp : int)
{
lives += powerUp;
health = maxHealth;
}
function AddHealth (powerUp : int)
{
health += powerUp;
if (health>maxHealth) // We can only show six segments in our HUD.
{
health=maxHealth;
}
}
function FoundBlue (numFound: int)
{
BlueGemsOwned += numFound;
// NOTE: We are deliberately not clamping this value to zero.
// This allows for levels where the number of pickups is greater than the target number needed.
// This also lets us speed up the testing process by temporarily reducing the collecatbles needed.
// Our HUD will clamp to zero for us.
}
function FoundYellow (numFound: int)
{
YellowGemsOwned += numFound;
}
function FoundGreen (numFound: int)
{
GreenGemsOwned += numFound;
}
function FoundRed (numFound: int)
{
RedGemsOwned += numFound;
}
function FalloutDeath ()
{
Die();
return;
}
function Die ()
{
// play the death sound if available.
if (deathSound)
{
AudioSource.PlayClipAtPoint(deathSound, transform.position);
}
lives--;
health = maxHealth;
if(lives < 0)
Application.LoadLevel("GameOver");
// If we've reached here, the player still has lives remaining, so respawn.
respawnPosition = Respawn.currentRespawn.transform.position;
Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too
// Hide the player briefly to give the death sound time to finish...
SendMessage("HidePlayer");
// Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider.
transform.position = respawnPosition + Vector3.up;
yield WaitForSeconds(1.6); // give the sound time to complete.
// (NOTE: "HidePlayer" also disables the player controls.)
SendMessage("ShowPlayer"); // Show the player again, ready for...
// ... the respawn point to play it's particle effect
Respawn.currentRespawn.FireEffect ();
}