- Home /
Timer script Update with Pickup
I am modifying the Lerpz tutorial to basically have a timer that updates when the player picks up the object. What is happening now is that the GUI starts with 20 seconds on the clock (adjusted in the inspector). However, every time the player picks up an object this GUI and variable, "emission" needs be updated by variable "forbiddenfruit". This is not happening. What is happening is that variable "emission" is constantly being added on never ceasing. I have attached the Emitter Script, an object of the particle system which is a child of the player as well as the ThirdpersonStatus script which includes the forbiddenfruit variable. Forbiddenfruit work perfectly as I've tested the output. Code: var emission = 0.1f; var emissionMod = 0.1f; var other : ThirdPersonStatus;
function Awake () {
other = FindObjectOfType(ThirdPersonStatus);
if (other == null) {
print("you haven't addd the component to the gameobject");
//emission +=other.forbiddenfruit;
}
}
function Update () {
if (emission > 0.1) {
emission -= ((emissionMod - other.forbiddenfruit)* Time.deltaTime);
print("float value = " + emission);
particleEmitter.minEmission = emission;
particleEmitter.maxEmission = emission;
}
else emission = 0;
}
Code:
// ThirdPersonStatus: Handles the player's state machine.
// Keeps track of inventory, health, lives, etc.
var health : int = 6;
var maxHealth : int = 6;
var lives : int;
var currentmultiplier = 10;
var forbiddenfruit : int;
var inc = 2;
var interactiontime : int;
// sound effects.
var struckSound: AudioClip;
var deathSound: AudioClip;
private var levelStateMachine : LevelStatus; // link to script that handles the level-complete sequence.
private var remainingItems : int; // total number to pick up on this level. Grabbed from LevelStatus.
function Awake()
{
levelStateMachine = FindObjectOfType(LevelStatus);
if (!levelStateMachine)
Debug.Log("No link to Level Status");
remainingItems = levelStateMachine.itemsNeeded;
remainingGems = levelStateMachine.gemsNeeded;
}
function Update()
{
if (lives <= 0 && Application.loadedLevel == 0)
{
Application.LoadLevel("TheGame");
}
}
// Utility function used by HUD script:
function GetRemainingItems() : int
{
//return remainingItems;
return forbiddenfruit;
}
function GetTimeLeft() : int
{
return interactiontime;
}
/*Window example*/
function AddLife (powerUp : int) // FUEL CELL COUNT - THE CURRENTMULTIPLIER SHOULD NOT BE USED
{
lives -= powerUp;
forbiddenfruit +=powerUp * 10;
//Debug.Log(forbiddenfruit);
//timeinc+=lives;
}
function FoundItem (numFound: int)
{
forbiddenfruit +=numFound * currentmultiplier;
//Debug.Log(forbiddenfruit);
//forbiddenfruit+= numFound * currentmultiplier;
// 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 ChangeOxygen ()
//{
//changeoxygenscript = FindObjectOfType(Emitter);
//changeoxygenscript.emission=changeoxy;
//changeoxy+=forbiddenfruit;
//}
function Increase () {
if(Application.loadedLevel == 0){
currentmultiplier = 10;
//Debug.Log(currentmultiplier);
}
else if(Application.loadedLevel == 1){
currentmultiplier = 20;
//Debug.Log(currentmultiplier);
}
else if(Application.loadedLevel == 2){
currentmultiplier = 30;
//Debug.Log(currentmultiplier);
}
else if(Application.loadedLevel == 3){
currentmultiplier = 40;
//Debug.Log(currentmultiplier);
}
else{
inc+=0;
}
}
function FalloutDeath ()
{
Die();
return;
}
function Die ()
{
// play the death sound if available.
if (deathSound)
{
AudioSource.PlayClipAtPoint(deathSound, transform.position);
}
if(lives <= 0)
Application.LoadLevel("TheGame");
// 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 ();
}
function LevelCompleted()
{
levelStateMachine.LevelCompleted();
}
Your answer
Follow this Question
Related Questions
3Dplatformer tutorial GUI script - adding a timer GUI 0 Answers
Timer script & game hud 0 Answers
Instantiating GUI text after 2nd object is destroyed 1 Answer
Lerpz Escapes question 1 Answer