Hi there,
I am using this script from Peneolpe tutorial to get additionnal life when the player collide with the game object it is attached to :
ParticlePickup.js
var emitter : ParticleEmitter;
var index : int;
var collectedParticle : GameObject;
private var sk : ChronoScoreKeeperKBNew00;
// OnTriggerEnter is called whenever a Collider hits this GameObject's collider
function OnTriggerEnter(other : Collider)
{
sk = other.GetComponent( ChronoScoreKeeperKBNew00 );
sk.Pickup( this );
}
// Collected is called when the player picks up this item.
function Collected()
{
// Spawn particles where the orb was collected
Instantiate( collectedParticle, transform.position, Quaternion.identity );
// Scale the particle down, so it is no longer visible
var particles : Particle[] = emitter.particles;
particles[ index ].size = 0;
emitter.particles = particles;
// Destroy the collider for this orb
Destroy( gameObject );
}
and I have this Function Pickup within a script (ChronoScoreKeeperKBNew00) attached to the player :
public function Pickup( pickup : ParticlePickup )
{
if ( playerInfo.health < playerInfo.maxHealth )
{
playerInfo.health++;
UpdateHealthGui();
pickup.Collected();
PlayAudioClip( pickupSound, pickup.transform.position, 1.0 );
}
else
{
var warning : GameObject = Instantiate( guiMessage );
warning.guiText.text = "You already have a six pack life";
Destroy(warning, 2);
}
}
What puzzles me is that everything works fine, I get the additionnal life when my player collides with this GO, I get the sound, I get the txt message if I already have the maxHealth, but I get a" null reference exception : Object reference not set to an instance of an object" which points to ParticlePickup script on the following line :
sk.Pickup( this );
Am I missing something here ??
thks in advance for your help .